From 756d37c1cc1624a27904ac992515ab3b6bfacdcf Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 9 Oct 2026 19:41:11 +0200 Subject: [PATCH 1/2] Skip deprecation warnings in parallel workers, dedupe per process --- src/Configuration/ECSConfigBuilder.php | 40 ++++++++++++------- .../DeprecatedPhpCsFixerSetsTest.php | 14 +++++++ 2 files changed, 40 insertions(+), 14 deletions(-) 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..341d7719f3 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); + } } From 8a27c5d06be8dbe7c031b79624457c9e0b5e63cf Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 9 Oct 2026 19:54:47 +0200 Subject: [PATCH 2/2] Use PHP 8.4 new without parentheses in test --- tests/Configuration/DeprecatedPhpCsFixerSetsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Configuration/DeprecatedPhpCsFixerSetsTest.php b/tests/Configuration/DeprecatedPhpCsFixerSetsTest.php index 341d7719f3..7fb7be61b7 100644 --- a/tests/Configuration/DeprecatedPhpCsFixerSetsTest.php +++ b/tests/Configuration/DeprecatedPhpCsFixerSetsTest.php @@ -26,7 +26,7 @@ public function testSkipsDeprecationWarningInParallelWorker(): void $_SERVER['argv'] = ['bin/ecs', 'worker', '--config', 'ecs.php']; ob_start(); - (new ECSConfigBuilder())->withEditorConfig(); + new ECSConfigBuilder()->withEditorConfig(); $output = ob_get_clean(); $_SERVER['argv'] = $originalArgv;