Skip to content

Commit 7dd79ad

Browse files
committed
[metrics] Add PhpMetrics command (#15)
1 parent dda83eb commit 7dd79ad

15 files changed

Lines changed: 1042 additions & 2 deletions

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ composer dev-tools tests
5353
composer dependencies
5454
vendor/bin/dev-tools dependencies
5555

56+
# Analyze code metrics with PhpMetrics
57+
composer metrics
58+
composer dev-tools metrics -- --report-html=build/metrics
59+
5660
# Check and fix code style using ECS and Composer Normalize
5761
composer dev-tools code-style
5862

@@ -102,6 +106,10 @@ The `dependencies` command ships with both dependency analyzers as direct
102106
dependencies of `fast-forward/dev-tools`, so it works without extra
103107
installation in the consumer project.
104108

109+
The `metrics` command ships with `phpmetrics/phpmetrics` as a direct
110+
dependency of `fast-forward/dev-tools`, so consumer repositories can generate
111+
metrics reports without extra setup.
112+
105113
The `skills` command keeps `.agents/skills` aligned with the packaged Fast
106114
Forward skill set. It creates missing links, repairs broken links, and
107115
preserves existing non-symlink directories. The `dev-tools:sync` command calls
@@ -115,6 +123,7 @@ automation assets.
115123
| `composer dev-tools` | Runs the full `standards` pipeline. |
116124
| `composer dev-tools tests` | Runs PHPUnit with local-or-packaged configuration. |
117125
| `composer dev-tools dependencies` | Reports missing and unused Composer dependencies. |
126+
| `composer dev-tools metrics` | Runs PhpMetrics and prints a reduced code-metrics summary. |
118127
| `composer dev-tools docs` | Builds the HTML documentation site from PSR-4 code and `docs/`. |
119128
| `composer dev-tools skills` | Creates or repairs packaged skill links in `.agents/skills`. |
120129
| `composer dev-tools gitattributes` | Manages export-ignore rules in .gitattributes. |

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"nikic/php-parser": "^5.7",
4343
"php-di/php-di": "^7.1",
4444
"php-parallel-lint/php-parallel-lint": "^1.4",
45+
"phpmetrics/phpmetrics": "^2.9",
4546
"phpdocumentor/shim": "^3.9",
4647
"phpro/grumphp-shim": "^2.19",
4748
"phpspec/prophecy": "^1.26",
@@ -113,6 +114,7 @@
113114
},
114115
"scripts": {
115116
"dev-tools": "dev-tools",
116-
"dev-tools:fix": "@dev-tools --fix"
117+
"dev-tools:fix": "@dev-tools --fix",
118+
"metrics": "@dev-tools metrics"
117119
}
118120
}

docs/commands/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Detailed documentation for each dev-tools command.
99
standards
1010
tests
1111
dependencies
12+
metrics
1213
code-style
1314
refactor
1415
phpdoc
@@ -22,4 +23,4 @@ Detailed documentation for each dev-tools command.
2223
license
2324
copy-resource
2425
git-hooks
25-
update-composer-json
26+
update-composer-json

docs/commands/metrics.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
metrics
2+
=======
3+
4+
Analyzes code metrics with PhpMetrics.
5+
6+
Overview
7+
--------
8+
9+
The ``metrics`` command runs `PhpMetrics <https://phpmetrics.github.io/website/>`_
10+
against the selected source directory, generates a JSON report, and prints a
11+
reduced summary with:
12+
13+
- average cyclomatic complexity by class;
14+
- average maintainability index by class;
15+
- number of classes analyzed;
16+
- number of functions analyzed.
17+
18+
Usage
19+
-----
20+
21+
.. code-block:: bash
22+
23+
composer metrics
24+
composer dev-tools metrics -- [options]
25+
vendor/bin/dev-tools metrics [options]
26+
27+
Options
28+
-------
29+
30+
``--src=<path>``
31+
Source directory to analyze.
32+
33+
Default: ``src``.
34+
35+
``--exclude=<list>``
36+
Comma-separated directories that should be excluded from analysis.
37+
38+
Default:
39+
``vendor,test,Test,tests,Tests,testing,Testing,bower_components,node_modules,cache,spec,build``.
40+
41+
``--report-html=<directory>``
42+
Optional output directory for the generated HTML report.
43+
44+
``--report-json=<file>``
45+
Optional output file for the generated JSON report.
46+
47+
``--cache-dir=<directory>``
48+
Cache directory used for temporary JSON reports when ``--report-json`` is
49+
not provided.
50+
51+
Default: ``tmp/cache/phpmetrics``.
52+
53+
Examples
54+
--------
55+
56+
Generate the reduced summary with defaults:
57+
58+
.. code-block:: bash
59+
60+
composer metrics
61+
62+
Generate an HTML report for manual inspection:
63+
64+
.. code-block:: bash
65+
66+
composer dev-tools metrics -- --report-html=build/metrics
67+
68+
Generate both JSON and HTML reports for CI artifacts:
69+
70+
.. code-block:: bash
71+
72+
vendor/bin/dev-tools metrics --report-json=build/metrics.json --report-html=build/metrics
73+
74+
Behavior
75+
--------
76+
77+
- the command fails early when ``vendor/bin/phpmetrics`` is not installed;
78+
- the source directory must exist;
79+
- the reduced summary is derived from the generated PhpMetrics JSON report;
80+
- optional HTML and JSON report destinations are created before execution.

docs/running/specialized-commands.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ Important details:
4242
- it returns a non-zero exit code when missing or unused dependencies are
4343
found.
4444

45+
``metrics``
46+
-----------
47+
48+
Analyzes code metrics with PhpMetrics.
49+
50+
.. code-block:: bash
51+
52+
composer metrics
53+
composer dev-tools metrics -- --report-html=build/metrics
54+
55+
Important details:
56+
57+
- it ships ``phpmetrics/phpmetrics`` as a direct dependency of
58+
``fast-forward/dev-tools``;
59+
- it prints a reduced summary with average cyclomatic complexity, average
60+
maintainability index, and analyzed class/function counts;
61+
- ``--report-html`` and ``--report-json`` allow persisting the native
62+
PhpMetrics reports for CI artifacts or manual review;
63+
- it fails early when the PhpMetrics binary or source directory is missing.
64+
4565
``code-style``
4666
--------------
4767

0 commit comments

Comments
 (0)