Skip to content

Commit 14b3d12

Browse files
[metrics] Add PhpMetrics command (#15) (#98)
* [metrics] Add PhpMetrics command (#15) * Update wiki submodule pointer for PR #98 * [metrics] Finalize metrics workflow and docs (#15) * Update wiki submodule pointer for PR #98 * [metrics] Align reports execution flow and tests (#15) * Update wiki submodule pointer for PR #98 --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent dda83eb commit 14b3d12

17 files changed

Lines changed: 600 additions & 16 deletions

File tree

.agents/skills/package-readme/SKILL.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This skill provides a comprehensive, reusable checklist and structure for creati
4444

4545
- **Badges**
4646
- Read [references/badges.md](references/badges.md) before drafting the badge block.
47-
- For current Fast Forward packages, default to this order: PHP Version, Composer Package, Tests, Coverage, Docs, License, GitHub Sponsors.
47+
- For current Fast Forward packages, default to this order: PHP Version, Composer Package, Tests, Coverage, Metrics, Docs, License, GitHub Sponsors.
4848
- Add a second standards row for relevant PSRs when the package contract is centered on them.
4949
- Keep Packagist visible both in the badge block via `Composer Package` and in the links section.
5050

@@ -54,6 +54,7 @@ This skill provides a comprehensive, reusable checklist and structure for creati
5454
[![Composer Package](https://img.shields.io/badge/composer-fast--forward%2Fcomponent-F28D1A.svg?logo=composer&logoColor=white)](https://packagist.org/packages/fast-forward/component)
5555
[![Tests](https://img.shields.io/github/actions/workflow/status/php-fast-forward/component/tests.yml?logo=githubactions&logoColor=white&label=tests&color=22C55E)](https://github.com/php-fast-forward/component/actions/workflows/tests.yml)
5656
[![Coverage](https://img.shields.io/badge/coverage-phpunit-4ADE80?logo=php&logoColor=white)](https://php-fast-forward.github.io/component/coverage/index.html)
57+
[![Metrics](https://img.shields.io/badge/metrics-phpmetrics-8B5CF6?logo=php&logoColor=white)](https://php-fast-forward.github.io/component/metrics/index.html)
5758
[![Docs](https://img.shields.io/github/deployments/php-fast-forward/component/github-pages?logo=readthedocs&logoColor=white&label=docs&labelColor=1E293B&color=38BDF8&style=flat)](https://php-fast-forward.github.io/component/index.html)
5859
[![License](https://img.shields.io/github/license/php-fast-forward/component?color=64748B)](LICENSE)
5960
[![GitHub Sponsors](https://img.shields.io/github/sponsors/php-fast-forward?logo=githubsponsors&logoColor=white&color=EC4899)](https://github.com/sponsors/php-fast-forward)
@@ -169,6 +170,7 @@ This skill provides a comprehensive, reusable checklist and structure for creati
169170
## 🔗 Links
170171
- [Repository](https://github.com/php-fast-forward/component)
171172
- [Packagist](https://packagist.org/packages/php-fast-forward/component)
173+
- [Metrics Report](https://php-fast-forward.github.io/component/metrics/index.html)
172174
- [RFC 2119](https://datatracker.ietf.org/doc/html/rfc2119)
173175
- [PSR-11](https://www.php-fig.org/psr/psr-11/)
174176
- [Sphinx Documentation](docs/index.rst)
@@ -205,7 +207,7 @@ This skill provides a comprehensive, reusable checklist and structure for creati
205207

206208
## Quick Review Checklist
207209
- [ ] Project title and short description
208-
- [ ] Badges follow the current Fast Forward stack: PHP Version, Composer Package, Tests, Coverage, Docs, License, GitHub Sponsors, plus relevant standards badges
210+
- [ ] Badges follow the current Fast Forward stack: PHP Version, Composer Package, Tests, Coverage, Metrics, Docs, License, GitHub Sponsors, plus relevant standards badges
209211
- [ ] Features (bulleted, with emoji)
210212
- [ ] Installation (composer, requirements)
211213
- [ ] Usage (basic and advanced)
@@ -217,7 +219,7 @@ This skill provides a comprehensive, reusable checklist and structure for creati
217219
- [ ] FAQ (if relevant)
218220
- [ ] License
219221
- [ ] Contributing
220-
- [ ] Links (repository, Packagist, docs, RFCs, PSRs)
222+
- [ ] Links (repository, Packagist, docs, metrics, RFCs, PSRs)
221223
- [ ] Comparison table (if relevant)
222224
- [ ] Formatting and style guidelines followed
223225
- [ ] SEO/discoverability (keywords, cross-links)

.github/wiki

Submodule wiki updated from c1a6da3 to 3ca041c

.github/workflows/reports.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
- name: Generate reports
7373
env:
7474
COMPOSER_ROOT_VERSION: ${{ env.REPORTS_ROOT_VERSION }}
75-
run: composer dev-tools reports -- --target=tmp/reports --coverage=tmp/reports/coverage
75+
run: composer dev-tools reports -- --target=tmp/reports --coverage=tmp/reports/coverage --metrics=tmp/reports/metrics
7676

7777
- name: Fix permissions
7878
run: |
@@ -139,6 +139,7 @@ jobs:
139139
140140
- Docs: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}/
141141
- Coverage: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}/coverage/
142+
- Metrics: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}/metrics/
142143
143144
cleanup_preview:
144145
if: github.event_name == 'pull_request' && github.event.action == 'closed'

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ across Fast Forward libraries.
88
[![Composer Package](https://img.shields.io/badge/composer-fast--forward%2Fdev--tools-F28D1A.svg?logo=composer&logoColor=white)](https://packagist.org/packages/fast-forward/dev-tools)
99
[![Tests](https://img.shields.io/github/actions/workflow/status/php-fast-forward/dev-tools/tests.yml?logo=githubactions&logoColor=white&label=tests&color=22C55E)](https://github.com/php-fast-forward/dev-tools/actions/workflows/tests.yml)
1010
[![Coverage](https://img.shields.io/badge/coverage-phpunit-4ADE80?logo=php&logoColor=white)](https://php-fast-forward.github.io/dev-tools/coverage/index.html)
11+
[![Metrics](https://img.shields.io/badge/metrics-phpmetrics-8B5CF6?logo=php&logoColor=white)](https://php-fast-forward.github.io/dev-tools/metrics/index.html)
1112
[![Docs](https://img.shields.io/github/deployments/php-fast-forward/dev-tools/github-pages?logo=readthedocs&logoColor=white&label=docs&labelColor=1E293B&color=38BDF8&style=flat)](https://php-fast-forward.github.io/dev-tools/index.html)
1213
[![License](https://img.shields.io/github/license/php-fast-forward/dev-tools?color=64748B)](LICENSE)
1314
[![GitHub Sponsors](https://img.shields.io/github/sponsors/php-fast-forward?logo=githubsponsors&logoColor=white&color=EC4899)](https://github.com/sponsors/php-fast-forward)
@@ -53,6 +54,11 @@ composer dev-tools tests
5354
composer dependencies
5455
vendor/bin/dev-tools dependencies
5556

57+
# Analyze code metrics with PhpMetrics
58+
composer metrics
59+
composer dev-tools metrics -- --report-html=build/metrics
60+
composer dev-tools metrics -- --working-dir=packages/example
61+
5662
# Check and fix code style using ECS and Composer Normalize
5763
composer dev-tools code-style
5864

@@ -70,6 +76,7 @@ composer dev-tools wiki
7076

7177
# Generate documentation frontpage and related reports
7278
composer dev-tools reports
79+
composer dev-tools reports -- --metrics
7380

7481
# Synchronize packaged agent skills into .agents/skills
7582
composer dev-tools skills
@@ -102,6 +109,10 @@ The `dependencies` command ships with both dependency analyzers as direct
102109
dependencies of `fast-forward/dev-tools`, so it works without extra
103110
installation in the consumer project.
104111

112+
The `metrics` command ships with `phpmetrics/phpmetrics` as a direct
113+
dependency of `fast-forward/dev-tools`, so consumer repositories can generate
114+
metrics reports without extra setup.
115+
105116
The `skills` command keeps `.agents/skills` aligned with the packaged Fast
106117
Forward skill set. It creates missing links, repairs broken links, and
107118
preserves existing non-symlink directories. The `dev-tools:sync` command calls
@@ -115,6 +126,7 @@ automation assets.
115126
| `composer dev-tools` | Runs the full `standards` pipeline. |
116127
| `composer dev-tools tests` | Runs PHPUnit with local-or-packaged configuration. |
117128
| `composer dev-tools dependencies` | Reports missing and unused Composer dependencies. |
129+
| `composer dev-tools metrics` | Runs PhpMetrics for a working directory and generates requested report artifacts. |
118130
| `composer dev-tools docs` | Builds the HTML documentation site from PSR-4 code and `docs/`. |
119131
| `composer dev-tools skills` | Creates or repairs packaged skill links in `.agents/skills`. |
120132
| `composer dev-tools gitattributes` | Manages export-ignore rules in .gitattributes. |

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"php-di/php-di": "^7.1",
4444
"php-parallel-lint/php-parallel-lint": "^1.4",
4545
"phpdocumentor/shim": "^3.9",
46+
"phpmetrics/phpmetrics": "^2.9",
4647
"phpro/grumphp-shim": "^2.19",
4748
"phpspec/prophecy": "^1.26",
4849
"phpspec/prophecy-phpunit": "^2.5",

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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 current working directory and forwards the requested report
11+
artifacts.
12+
13+
Usage
14+
-----
15+
16+
.. code-block:: bash
17+
18+
composer metrics
19+
composer dev-tools metrics -- [options]
20+
vendor/bin/dev-tools metrics [options]
21+
22+
Options
23+
-------
24+
25+
``--working-dir=<path>``
26+
Composer's inherited working-directory option. Use it when you want to run
27+
the command from another directory without changing your current shell
28+
session.
29+
30+
Default: the current working directory.
31+
32+
``--exclude=<list>``
33+
Comma-separated directories that should be excluded from analysis.
34+
35+
Default:
36+
``vendor,test,tests,tmp,cache,spec,build,backup,resources``.
37+
38+
``--report-html=<directory>``
39+
Optional output directory for the generated HTML report.
40+
41+
``--report-json=<file>``
42+
Optional output file for the generated JSON report.
43+
44+
``--report-summary-json=<file>``
45+
Optional output file for the generated summary JSON report.
46+
47+
Examples
48+
--------
49+
50+
Analyze the current repository with defaults:
51+
52+
.. code-block:: bash
53+
54+
composer metrics
55+
56+
Generate an HTML report for manual inspection:
57+
58+
.. code-block:: bash
59+
60+
composer dev-tools metrics -- --report-html=build/metrics
61+
62+
Generate JSON and HTML reports for CI artifacts:
63+
64+
.. code-block:: bash
65+
66+
vendor/bin/dev-tools metrics --report-json=build/metrics.json --report-html=build/metrics
67+
68+
Behavior
69+
--------
70+
71+
- the command forwards report options directly to PhpMetrics;
72+
- it runs PhpMetrics through the active PHP binary and suppresses PhpMetrics
73+
deprecation notices emitted by the dependency itself.

docs/commands/reports.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ coverage. It combines:
1111

1212
- ``docs --target`` - generates API documentation
1313
- ``tests --coverage`` - generates test coverage reports
14+
- optionally ``metrics --report-html`` - generates PhpMetrics HTML reports
1415

1516
These are run in parallel for efficiency.
1617

@@ -34,6 +35,10 @@ Options
3435
The target directory for the generated test coverage report.
3536
Default: ``public/coverage``.
3637

38+
``--metrics`` (optional)
39+
Generate the metrics HTML report. When passed without a value, the report is
40+
generated in ``public/metrics``.
41+
3742
Examples
3843
--------
3944

@@ -49,6 +54,13 @@ Generate to custom directories:
4954
5055
composer reports --target=build --coverage=build/coverage
5156
57+
Generate reports including metrics:
58+
59+
.. code-block:: bash
60+
61+
composer reports --metrics
62+
composer reports --metrics=build/metrics
63+
5264
Exit Codes
5365
---------
5466

@@ -66,6 +78,7 @@ Behavior
6678
---------
6779

6880
- Runs ``docs`` and ``tests --coverage`` in parallel.
81+
- Runs ``metrics --report-html`` in parallel when ``--metrics`` is enabled.
6982
- Runs tests with ``--no-progress`` and ``--coverage-summary`` so report builds
7083
keep PHPUnit output concise.
7184
- Used by the ``standards`` command as the final phase.

docs/running/specialized-commands.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ 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+
composer dev-tools metrics -- --working-dir=packages/example
55+
56+
Important details:
57+
58+
- it ships ``phpmetrics/phpmetrics`` as a direct dependency of
59+
``fast-forward/dev-tools``;
60+
- it analyzes the selected ``--working-dir`` and forwards the requested
61+
report options directly to PhpMetrics;
62+
- ``--report-html``, ``--report-json``, and ``--report-summary-json`` allow
63+
persisting the native PhpMetrics reports for CI artifacts or manual review;
64+
- it suppresses deprecation notices emitted by the PhpMetrics dependency
65+
itself so the command output stays readable.
66+
4567
``code-style``
4668
--------------
4769

@@ -139,6 +161,7 @@ Important details:
139161

140162
- it calls ``docs --target public``;
141163
- it calls ``tests --coverage public/coverage --no-progress --coverage-summary``;
164+
- ``--metrics`` adds ``metrics --report-html public/metrics``;
142165
- it is the reporting stage used by ``standards``.
143166

144167
``skills``

0 commit comments

Comments
 (0)