Skip to content

Commit 2c13bf8

Browse files
committed
fix: keep phpmetrics composer analysis bounded
1 parent d41f268 commit 2c13bf8

5 files changed

Lines changed: 29 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
### Fixed
1616

17-
- Preserve color-friendly nested command environments, explicit Symfony Console ANSI flags, concise process section labels, and offline-safe PhpMetrics execution without restoring PTY (#239)
17+
- Preserve color-friendly nested command environments, explicit Symfony Console ANSI flags, concise process section labels, and fixture-safe PhpMetrics execution with bounded Packagist lookups without restoring PTY (#239)
1818
- Disable Xdebug for queued child processes unless coverage requires it without PCOV, reducing repeated Composer Xdebug warnings in orchestrated commands (#239)
1919
- Keep the reports workflow permission warning loop shell-safe for paths containing backslashes (#244)
2020
- Keep required PHPUnit matrix checks reporting after workflow-managed `.github/wiki` pointer commits by running the pull-request test workflow without top-level path filters and aligning the packaged consumer test wrapper (#230)

docs/commands/metrics.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Options
3333
Comma-separated directories that should be excluded from analysis.
3434

3535
Default:
36-
``vendor,test,tests,tmp,cache,spec,build,.dev-tools,backup,resources``.
36+
``vendor,tmp,cache,spec,build,.dev-tools,backup,resources,tests/Fixtures``.
3737

3838
``--target=<directory>``
3939
Output directory for the generated metrics reports.
@@ -94,5 +94,8 @@ Behavior
9494
running PhpMetrics in a quieter mode to avoid polluting the captured payload;
9595
- it runs PhpMetrics through the active PHP binary and suppresses PhpMetrics
9696
deprecation notices emitted by the dependency itself;
97-
- it disables PhpMetrics' Composer package freshness lookup so metrics runs do
98-
not block on Packagist availability or local network state.
97+
- it keeps PhpMetrics' Composer analysis enabled so the reports include package
98+
metadata from the root ``composer.json`` and ``composer.lock``, while the
99+
default exclusions keep nested fixture projects out of that Composer scan;
100+
- it limits PhpMetrics' per-package Packagist socket wait so package freshness
101+
enrichment cannot leave metrics generation stuck indefinitely.

docs/running/specialized-commands.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ Important details:
133133
available;
134134
- it suppresses deprecation notices emitted by the PhpMetrics dependency
135135
itself so the command output stays readable;
136-
- it disables PhpMetrics' Composer package freshness lookup so report
137-
generation does not depend on Packagist connectivity.
136+
- it keeps PhpMetrics' Composer analysis enabled so report generation includes
137+
root package metadata, while default exclusions keep nested fixture projects
138+
out of that Composer scan;
139+
- it limits PhpMetrics' per-package Packagist socket wait so package freshness
140+
enrichment cannot leave report generation stuck indefinitely.
138141

139142
``code-style``
140143
--------------

src/Console/Command/MetricsCommand.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ final class MetricsCommand extends BaseCommand implements LoggerAwareCommandInte
5050
*/
5151
private const int PHP_ERROR_REPORTING = \E_ALL & ~\E_DEPRECATED;
5252

53+
/**
54+
* @var int the maximum seconds PhpMetrics may wait on each Packagist package lookup
55+
*/
56+
private const int PHP_DEFAULT_SOCKET_TIMEOUT = 1;
57+
5358
/**
5459
* @param ProcessBuilderInterface $processBuilder the builder used to assemble the PhpMetrics process
5560
* @param ProcessQueueInterface $processQueue the queue used to execute the PhpMetrics process
@@ -80,7 +85,7 @@ protected function configure(): void
8085
name: 'exclude',
8186
mode: InputOption::VALUE_OPTIONAL,
8287
description: 'Comma-separated directories that SHOULD be excluded from analysis.',
83-
default: 'vendor,test,tests,tmp,cache,spec,build,.dev-tools,backup,resources',
88+
default: 'vendor,tmp,cache,spec,build,.dev-tools,backup,resources,tests/Fixtures',
8489
)
8590
->addOption(
8691
name: 'target',
@@ -118,7 +123,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
118123
$processBuilder = $this->processBuilder
119124
->withArgument('--ansi')
120125
->withArgument('--git', 'git')
121-
->withArgument('--composer', 'false')
122126
->withArgument('--exclude', $exclude)
123127
->withArgument('--report-html', $target)
124128
->withArgument('--report-json', $target . '/report.json')
@@ -135,7 +139,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
135139
$this->processQueue->add(
136140
process: $processBuilder
137141
->withArgument('.')
138-
->build([\PHP_BINARY, '-derror_reporting=' . self::PHP_ERROR_REPORTING, self::BINARY]),
142+
->build([
143+
\PHP_BINARY,
144+
'-derror_reporting=' . self::PHP_ERROR_REPORTING,
145+
'-ddefault_socket_timeout=' . self::PHP_DEFAULT_SOCKET_TIMEOUT,
146+
self::BINARY,
147+
]),
139148
label: 'Generating Metrics with PhpMetrics',
140149
);
141150

tests/Console/Command/MetricsCommandTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function setUp(): void
7373
$this->process = $this->prophesize(Process::class);
7474

7575
$this->input->getOption('exclude')
76-
->willReturn('vendor,tests');
76+
->willReturn('vendor,tests/Fixtures');
7777
$this->input->getOption('target')
7878
->willReturn(ManagedWorkspace::getOutputDirectory(ManagedWorkspace::METRICS));
7979
$this->input->getOption('junit')
@@ -94,10 +94,10 @@ protected function setUp(): void
9494
$this->processBuilder->withArgument(Argument::any(), Argument::any())->willReturn(
9595
$this->processBuilder->reveal()
9696
);
97-
$this->processBuilder->withArgument('--composer', 'false')
98-
->willReturn($this->processBuilder->reveal())
99-
->shouldBeCalled();
100-
$this->processBuilder->build(Argument::any())->willReturn($this->process->reveal());
97+
$this->processBuilder->build(Argument::that(static fn(array $command): bool => \PHP_BINARY === $command[0]
98+
&& str_starts_with((string) $command[1], '-derror_reporting=')
99+
&& '-ddefault_socket_timeout=1' === $command[2]
100+
&& 'vendor/bin/phpmetrics' === $command[3]))->willReturn($this->process->reveal());
101101
$this->processQueue->add($this->process->reveal(), Argument::cetera())
102102
->shouldBeCalled();
103103

0 commit comments

Comments
 (0)