diff --git a/src/Configuration/ECSConfigBuilder.php b/src/Configuration/ECSConfigBuilder.php index c3647418d6..df1f622571 100644 --- a/src/Configuration/ECSConfigBuilder.php +++ b/src/Configuration/ECSConfigBuilder.php @@ -319,16 +319,9 @@ public function withPreparedSets( */ public function withPhpCsFixerSets(bool ...$sets): self { - // config file is required twice (container build + cache hash), warn only once per process - static $warned = false; - if (! $warned) { - $warned = true; - - $outputPrinter = new OutputPrinter(new OutputColorizer()); - $outputPrinter->warning( - 'The "withPhpCsFixerSets()" method is deprecated. Use ->withPreparedSets() or ->withSets() with prepared sets instead.' - ); - } + $this->printDeprecationWarning( + 'The "withPhpCsFixerSets()" method is deprecated. Use ->withPreparedSets() or ->withSets() with prepared sets instead.' + ); return $this; } @@ -376,8 +369,7 @@ public function withCache(?string $directory = null, ?string $namespace = null): */ public function withEditorConfig(): self { - $outputPrinter = new OutputPrinter(new OutputColorizer()); - $outputPrinter->warning( + $this->printDeprecationWarning( 'The "withEditorConfig()" method is deprecated, as it leaks project-wide settings into ECS. Configure the matching PHP-CS-Fixer rules explicitly instead.' ); return $this; @@ -439,13 +431,33 @@ public function withoutParallel(): self */ public function withRealPathReporting(): self { - $outputPrinter = new OutputPrinter(new OutputColorizer()); - $outputPrinter->warning( + $this->printDeprecationWarning( 'The "withRealPathReporting()" method is deprecated. Use the JSON output format ("--output-format json") to get absolute paths.' ); return $this; } + /** + * Skips parallel worker processes, so the main command prints each deprecation once. + */ + private function printDeprecationWarning(string $message): void + { + if (($_SERVER['argv'][1] ?? null) === 'worker') { + return; + } + + // config file is loaded twice per process (container build + cache hash), warn only once + static $printedMessages = []; + if (isset($printedMessages[$message])) { + return; + } + + $printedMessages[$message] = true; + + $outputPrinter = new OutputPrinter(new OutputColorizer()); + $outputPrinter->warning($message); + } + /** * Raise your spacing coverage from the safest rules * to more affecting ones, one level at a time. diff --git a/tests/Configuration/DeprecatedPhpCsFixerSetsTest.php b/tests/Configuration/DeprecatedPhpCsFixerSetsTest.php index 3628cc2c79..7fb7be61b7 100644 --- a/tests/Configuration/DeprecatedPhpCsFixerSetsTest.php +++ b/tests/Configuration/DeprecatedPhpCsFixerSetsTest.php @@ -19,4 +19,18 @@ public function testAcceptsLegacyNamedArgumentsWithoutCrashing(): void self::assertSame($ecsConfigBuilder, $result); } + + public function testSkipsDeprecationWarningInParallelWorker(): void + { + $originalArgv = $_SERVER['argv']; + $_SERVER['argv'] = ['bin/ecs', 'worker', '--config', 'ecs.php']; + + ob_start(); + new ECSConfigBuilder()->withEditorConfig(); + $output = ob_get_clean(); + + $_SERVER['argv'] = $originalArgv; + + self::assertSame('', $output); + } }