diff --git a/src/Runner/Parallel/ParallelisationException.php b/src/Runner/Parallel/ParallelisationException.php index 28a4b8ab9b7..4b7d2842698 100644 --- a/src/Runner/Parallel/ParallelisationException.php +++ b/src/Runner/Parallel/ParallelisationException.php @@ -25,7 +25,7 @@ final class ParallelisationException extends \RuntimeException { public static function forUnknownIdentifier(ProcessIdentifier $identifier): self { - return new self('Unknown process identifier: '.(string) $identifier); + return new self('Unknown process identifier: '.$identifier->toString()); } /** diff --git a/src/Runner/Parallel/ProcessFactory.php b/src/Runner/Parallel/ProcessFactory.php index d737b5c3880..64de299f93b 100644 --- a/src/Runner/Parallel/ProcessFactory.php +++ b/src/Runner/Parallel/ProcessFactory.php @@ -80,7 +80,7 @@ public function getCommandArgs(int $serverPort, ProcessIdentifier $identifier, R '--port', (string) $serverPort, '--identifier', - escapeshellarg((string) $identifier), + escapeshellarg($identifier->toString()), ]; if ($runnerConfig->isDryRun()) { diff --git a/src/Runner/Parallel/ProcessIdentifier.php b/src/Runner/Parallel/ProcessIdentifier.php index 03bb11df433..469c665d582 100644 --- a/src/Runner/Parallel/ProcessIdentifier.php +++ b/src/Runner/Parallel/ProcessIdentifier.php @@ -21,7 +21,7 @@ * * @internal */ -final class ProcessIdentifier implements \Stringable +final class ProcessIdentifier { private const IDENTIFIER_PREFIX = 'php-cs-fixer_parallel_'; @@ -32,7 +32,7 @@ private function __construct(string $identifier) $this->identifier = $identifier; } - public function __toString(): string + public function toString(): string { return $this->identifier; } diff --git a/src/Runner/Parallel/ProcessPool.php b/src/Runner/Parallel/ProcessPool.php index d48f9edcd18..ef4bcf3802c 100644 --- a/src/Runner/Parallel/ProcessPool.php +++ b/src/Runner/Parallel/ProcessPool.php @@ -45,21 +45,21 @@ public function __construct(ServerInterface $server, ?callable $onServerClose = public function getProcess(ProcessIdentifier $identifier): Process { - if (!isset($this->processes[(string) $identifier])) { + if (!isset($this->processes[$identifier->toString()])) { throw ParallelisationException::forUnknownIdentifier($identifier); } - return $this->processes[(string) $identifier]; + return $this->processes[$identifier->toString()]; } public function addProcess(ProcessIdentifier $identifier, Process $process): void { - $this->processes[(string) $identifier] = $process; + $this->processes[$identifier->toString()] = $process; } public function endProcessIfKnown(ProcessIdentifier $identifier): void { - if (!isset($this->processes[(string) $identifier])) { + if (!isset($this->processes[$identifier->toString()])) { return; } @@ -77,7 +77,7 @@ private function endProcess(ProcessIdentifier $identifier): void { $this->getProcess($identifier)->quit(); - unset($this->processes[(string) $identifier]); + unset($this->processes[$identifier->toString()]); if (0 === \count($this->processes)) { $this->server->close(); diff --git a/tests/Console/Command/WorkerCommandTest.php b/tests/Console/Command/WorkerCommandTest.php index 04ade0f6a6f..049a238f062 100644 --- a/tests/Console/Command/WorkerCommandTest.php +++ b/tests/Console/Command/WorkerCommandTest.php @@ -59,13 +59,13 @@ public function testMissingPortCausesFailure(): void self::expectException(ParallelisationException::class); self::expectExceptionMessage('Missing parallelisation options'); - $commandTester = $this->doTestExecute(['--identifier' => (string) ProcessIdentifier::create()]); + $commandTester = $this->doTestExecute(['--identifier' => ProcessIdentifier::create()->toString()]); } public function testWorkerCantConnectToServerWhenExecutedDirectly(): void { $commandTester = $this->doTestExecute([ - '--identifier' => (string) ProcessIdentifier::create(), + '--identifier' => ProcessIdentifier::create()->toString(), '--port' => 12_345, ]); @@ -107,7 +107,7 @@ public function testWorkerCommunicatesWithTheServer(): void * } $workerScope */ $workerScope = [ - 'identifier' => (string) $processIdentifier, + 'identifier' => $processIdentifier->toString(), 'messages' => [], 'connected' => false, 'chunkRequested' => false, diff --git a/tests/Runner/Parallel/ProcessFactoryTest.php b/tests/Runner/Parallel/ProcessFactoryTest.php index 8e561c2e539..32f583f92cc 100644 --- a/tests/Runner/Parallel/ProcessFactoryTest.php +++ b/tests/Runner/Parallel/ProcessFactoryTest.php @@ -80,7 +80,7 @@ public function testCreate(array $input, RunnerConfig $config, string $expectedA trim( sprintf( 'worker --port 1234 --identifier \'%s\' %s', - (string) $identifier, + $identifier->toString(), trim($expectedAdditionalArgs) ) ), diff --git a/tests/Runner/Parallel/ProcessIdentifierTest.php b/tests/Runner/Parallel/ProcessIdentifierTest.php index c3d6450dbad..c90c0951c17 100644 --- a/tests/Runner/Parallel/ProcessIdentifierTest.php +++ b/tests/Runner/Parallel/ProcessIdentifierTest.php @@ -29,7 +29,7 @@ public function testCreateIdentifier(): void { $identifier = ProcessIdentifier::create(); - self::assertStringStartsWith('php-cs-fixer_parallel_', (string) $identifier); + self::assertStringStartsWith('php-cs-fixer_parallel_', $identifier->toString()); } /** @@ -42,7 +42,7 @@ public function testFromRaw(string $rawIdentifier, bool $valid): void } $identifier = ProcessIdentifier::fromRaw($rawIdentifier); - self::assertSame($rawIdentifier, (string) $identifier); + self::assertSame($rawIdentifier, $identifier->toString()); } /**