Skip to content

Commit 5d86394

Browse files
committed
[metrics] Finalize metrics workflow and docs (#15)
1 parent 515f5b6 commit 5d86394

22 files changed

Lines changed: 202 additions & 688 deletions

.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/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: 4 additions & 1 deletion
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)
@@ -56,6 +57,7 @@ vendor/bin/dev-tools dependencies
5657
# Analyze code metrics with PhpMetrics
5758
composer metrics
5859
composer dev-tools metrics -- --report-html=build/metrics
60+
composer dev-tools metrics -- --working-dir=packages/example
5961

6062
# Check and fix code style using ECS and Composer Normalize
6163
composer dev-tools code-style
@@ -74,6 +76,7 @@ composer dev-tools wiki
7476

7577
# Generate documentation frontpage and related reports
7678
composer dev-tools reports
79+
composer dev-tools reports -- --metrics
7780

7881
# Synchronize packaged agent skills into .agents/skills
7982
composer dev-tools skills
@@ -123,7 +126,7 @@ automation assets.
123126
| `composer dev-tools` | Runs the full `standards` pipeline. |
124127
| `composer dev-tools tests` | Runs PHPUnit with local-or-packaged configuration. |
125128
| `composer dev-tools dependencies` | Reports missing and unused Composer dependencies. |
126-
| `composer dev-tools metrics` | Runs PhpMetrics and prints a reduced code-metrics summary. |
129+
| `composer dev-tools metrics` | Runs PhpMetrics for a working directory and generates requested report artifacts. |
127130
| `composer dev-tools docs` | Builds the HTML documentation site from PSR-4 code and `docs/`. |
128131
| `composer dev-tools skills` | Creates or repairs packaged skill links in `.agents/skills`. |
129132
| `composer dev-tools gitattributes` | Manages export-ignore rules in .gitattributes. |

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
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",
4645
"phpdocumentor/shim": "^3.9",
46+
"phpmetrics/phpmetrics": "^2.9",
4747
"phpro/grumphp-shim": "^2.19",
4848
"phpspec/prophecy": "^1.26",
4949
"phpspec/prophecy-phpunit": "^2.5",
@@ -114,7 +114,6 @@
114114
},
115115
"scripts": {
116116
"dev-tools": "dev-tools",
117-
"dev-tools:fix": "@dev-tools --fix",
118-
"metrics": "@dev-tools metrics"
117+
"dev-tools:fix": "@dev-tools --fix"
119118
}
120119
}

docs/commands/metrics.rst

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ Overview
77
--------
88

99
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.
10+
against the current working directory and forwards the requested report
11+
artifacts.
1712

1813
Usage
1914
-----
@@ -27,33 +22,32 @@ Usage
2722
Options
2823
-------
2924

30-
``--src=<path>``
31-
Source directory to analyze.
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.
3229

33-
Default: ``src``.
30+
Default: the current working directory.
3431

3532
``--exclude=<list>``
3633
Comma-separated directories that should be excluded from analysis.
3734

3835
Default:
39-
``vendor,test,Test,tests,Tests,testing,Testing,bower_components,node_modules,cache,spec,build``.
36+
``vendor,test,tests,tmp,cache,spec,build,backup,resources``.
4037

4138
``--report-html=<directory>``
4239
Optional output directory for the generated HTML report.
4340

4441
``--report-json=<file>``
4542
Optional output file for the generated JSON report.
4643

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``.
44+
``--report-summary-json=<file>``
45+
Optional output file for the generated summary JSON report.
5246

5347
Examples
5448
--------
5549

56-
Generate the reduced summary with defaults:
50+
Analyze the current repository with defaults:
5751

5852
.. code-block:: bash
5953
@@ -65,7 +59,7 @@ Generate an HTML report for manual inspection:
6559
6660
composer dev-tools metrics -- --report-html=build/metrics
6761
68-
Generate both JSON and HTML reports for CI artifacts:
62+
Generate JSON and HTML reports for CI artifacts:
6963

7064
.. code-block:: bash
7165
@@ -74,7 +68,6 @@ Generate both JSON and HTML reports for CI artifacts:
7468
Behavior
7569
--------
7670

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.
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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,18 @@ Analyzes code metrics with PhpMetrics.
5151
5252
composer metrics
5353
composer dev-tools metrics -- --report-html=build/metrics
54+
composer dev-tools metrics -- --working-dir=packages/example
5455
5556
Important details:
5657

5758
- it ships ``phpmetrics/phpmetrics`` as a direct dependency of
5859
``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.
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.
6466

6567
``code-style``
6668
--------------
@@ -159,6 +161,7 @@ Important details:
159161

160162
- it calls ``docs --target public``;
161163
- it calls ``tests --coverage public/coverage --no-progress --coverage-summary``;
164+
- ``--metrics`` adds ``metrics --report-html public/metrics``;
162165
- it is the reporting stage used by ``standards``.
163166

164167
``skills``

0 commit comments

Comments
 (0)