andrey-tech / pdepend-summary-formatter-php
一个工具,用于在控制台和CI/CD流水线中显示由PHP Depend测量的软件代码质量指标
Requires
- php: ^7.4 || ^8.0
- ext-simplexml: *
- symfony/console: ^4.4 || ^5.4 || ^6.3 || ^7.1
- symfony/yaml: ^4.4 || ^5.4 || ^6.3 || ^7.1
Requires (Dev)
- overtrue/phplint: ^3.4 || ^9.0
- pdepend/pdepend: ^2.15
- phpmd/phpmd: ^2.14
- slevomat/coding-standard: ^8.13
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^5.15
Suggests
- phpmd/phpmd: PHPMD is a spin-off project of PHP Depend
Conflicts
- pdepend/pdepend: <2.15
README
Pdepend Summary Formatter是一个工具,用于在控制台和CI/CD流水线中显示由PHP Depend(pdepend)测量的软件代码质量指标。
目录
安装
Pdepend Summary Formatter工具需要 PHP >= 7.4、最新版本的PHP Depend和Composer。
composer require --dev pdepend/pdepend:"^2.15"
composer require --dev andrey-tech/pdepend-summary-formatter-php
在当前工作目录中生成默认配置文件 pdepend-summary-formatter.yml.dist
./vendor/bin/pdepend-summary-formatter --init
然后运行 PHP Depend
扫描目录 src
中的源PHP代码,并在文件 summary.xml
中生成XML报告
./vendor/bin/pdepend --summary-xml=summary.xml --suffix=php src
然后运行Pdepend Summary Formatter工具来显示由PHP Depend测量的代码质量指标,并在指定的文本文件 summary.txt
中写入结果
./vendor/bin/pdepend-summary-formatter summary.xml --output-file=summary.txt
命令行选项
./vendor/bin/pdepend-summary-formatter <path to pdepend file summary.xml>
Pdepend Summary Formatter工具的命令行界面也接受以下可选参数
--init
— 将在当前工作目录中生成默认配置文件pdepend-summary-formatter.yml.dist
。--output-file=
— 将结果也写入指定的文本文件。--config-file=
— 自定义配置YAML文件的文件路径。--ignore-red-metrics-on-exit
— 即使存在“红色”指标,也将以零退出代码退出。--ignore-yellow-metrics-on-exit
— 即使存在“黄色”指标,也将以零退出代码退出。--no-colors
— 在控制台中禁用颜色。
Pdepend Summary Formatter工具和PHP Depend工具的示例命令行
./vendor/bin/pdepend --summary-xml=./var/summary.xml --suffix=php src,tests ./vendor/bin/pdepend-summary-formatter ./var/summary.xml --config-file=./pdepend-summary-formatter.yml --output-file=./var/summary.txt
示例输出文本文件 summary.txt
FILE: src/AndreyTech/Pdepend/Summary/Formatter/Colorizer.php
+---------------------------+-----+-----+-----+-----+-----+-----+------+-----+------+
| CLASS | wmc | cbo | loc | cis | nom | npm | vars | dit | nocc |
+---------------------------+-----+-----+-----+-----+-----+-----+------+-----+------+
| Colorizer | 15 | 0 | 117 | 4 | 8 | 4 | 3 | 0 | 0 |
+---------------------------+-----+-----+-----+-----+-----+-----+------+-----+------+
+---------------------------+----+-----+------+-------+-------+-----+------+----+-----+------+-----+----+-----+-----+-----+
| METHOD | mi | ccn | ccn2 | crap0 | npath | loc | hb | hd | hv | he | ht | hi | hl | hnd | hnt |
+---------------------------+----+-----+------+-------+-------+-----+------+----+-----+------+-----+----+-----+-----+-----+
| __construct | 81 | 1 | 1 | 2 | 1 | 4 | 0.01 | 4 | 16 | 62 | 3 | 4 | 0.3 | 6 | 6 |
| getFgTagStats | 82 | 1 | 1 | 2 | 1 | 4 | 0.01 | 8 | 12 | 93 | 5 | 1 | 0.1 | 5 | 5 |
| colorizeClassMetric | 79 | 1 | 1 | 2 | 1 | 4 | 0.01 | 5 | 37 | 192 | 11 | 7 | 0.2 | 10 | 11 |
| colorizeMethodMetric | 79 | 1 | 1 | 2 | 1 | 4 | 0.01 | 5 | 37 | 192 | 11 | 7 | 0.2 | 10 | 11 |
| colorize | 57 | 4 | 5 | 30 | 8 | 19 | 0.14 | 27 | 315 | 8517 | 473 | 12 | 0 | 32 | 63 |
| renderTemplate | 59 | 3 | 3 | 12 | 4 | 17 | 0.09 | 14 | 320 | 4379 | 243 | 23 | 0.1 | 25 | 69 |
| updateFgTagStats | 70 | 2 | 2 | 6 | 2 | 8 | 0.05 | 23 | 78 | 1813 | 101 | 3 | 0 | 13 | 21 |
| parseConfig | 73 | 1 | 1 | 2 | 1 | 16 | 0.03 | 7 | 96 | 660 | 37 | 14 | 0.1 | 13 | 26 |
+---------------------------+----+-----+------+-------+-------+-----+------+----+-----+------+-----+----+-----+-----+-----+
+---------------------+--------+--------+--------+--------+-----+-----+-----+-----+-----+------+------+-------+
| PROJECT | min mi | avg mi | max mi | std mi | noc | nom | noi | nof | nop | loc | lloc | ncloc |
+---------------------+--------+--------+--------+--------+-----+-----+-----+-----+-----+------+------+-------+
| 2023-10-04T17:15:14 | 57 | 72 | 82 | 9 | 11 | 74 | 0 | 0 | 2 | 1376 | 501 | 1250 |
+---------------------+--------+--------+--------+--------+-----+-----+-----+-----+-----+------+------+-------+
软件指标
PHP Depend (pdepend)工具可以从给定的代码库生成大量软件指标。这些值可以用来衡量软件项目的质量,并有助于识别应用重构的应用程序部分。
Pdepend Summary Formatter工具仅显示由PHP Depend测量的软件指标的一部分,并根据配置YAML文件中定义的值界限,在控制台中以绿色、黄色和红色颜色显示。
此表显示了Pdepend Summary Formatter工具为整个项目、类、特质、方法显示的软件指标列表。该表还显示了基于PHP Mess Detector (PHPMD)工具的软件指标的默认“红色”界限。
注意:✓ — 表示此指标没有定义“红色”颜色界限。
配置YAML文件
默认情况下,Pdepend Summary Formatter工具在当前工作目录中查找以下配置YAML文件
pdepend-summary-formatter.yml
,pdepend-summary-formatter.yml.dist
.
配置YAML文件允许设置软件指标值的颜色界限。
Pdepend Summary Formatter工具当前定义了三个颜色界限
白色值表示此指标没有定义颜色界限。
您还可以添加/设置自定义颜色和样式。请参阅Symfony控制台中的如何为控制台输出着色和设置样式。
默认配置文件片段
metrics: # Metrics of class class: # https://learn.microsoft.com/en-us/visualstudio/code-quality/code-metrics-class-coupling?view=vs-2022 # https://phpmd.org/rules/design.html#couplingbetweenobjects # https://pdepend.org/documentation/software-metrics/coupling-between-objects.html cbo: green: [ 0, 13 ], red+bold: [ 14, null ] # Metrics of method method: # https://learn.microsoft.com/en-us/visualstudio/code-quality/code-metrics-cyclomatic-complexity?view=vs-2022 # https://phpmd.org/rules/codesize.html#cyclomaticcomplexity ccn: green: [ 1, 7 ] yellow+bold: [ 8, 10 ] red+bold: [ 11, null ]
退出代码
Pdepend Summary Formatter工具目前定义了四种不同的退出代码
作者和维护者
Pdepend Summary Formatter工具的作者和维护者是andrey-tech。
许可证
本工具遵循MIT许可协议。