Skip to content

Commit

Permalink
Explicit ->toString() conversion for process identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Wirone committed May 8, 2024
1 parent 5b4c33b commit 1e2f05f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Runner/Parallel/ParallelisationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Parallel/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions src/Runner/Parallel/ProcessIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @internal
*/
final class ProcessIdentifier implements \Stringable
final class ProcessIdentifier
{
private const IDENTIFIER_PREFIX = 'php-cs-fixer_parallel_';

Expand All @@ -32,7 +32,7 @@ private function __construct(string $identifier)
$this->identifier = $identifier;
}

public function __toString(): string
public function toString(): string
{
return $this->identifier;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Runner/Parallel/ProcessPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions tests/Console/Command/WorkerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);

Expand Down Expand Up @@ -107,7 +107,7 @@ public function testWorkerCommunicatesWithTheServer(): void
* } $workerScope
*/
$workerScope = [
'identifier' => (string) $processIdentifier,
'identifier' => $processIdentifier->toString(),
'messages' => [],
'connected' => false,
'chunkRequested' => false,
Expand Down
2 changes: 1 addition & 1 deletion tests/Runner/Parallel/ProcessFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
),
Expand Down
4 changes: 2 additions & 2 deletions tests/Runner/Parallel/ProcessIdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand Down

0 comments on commit 1e2f05f

Please sign in to comment.