Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions src/Configuration/ECSConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions tests/Configuration/DeprecatedPhpCsFixerSetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading