Skip to content

Commit 6f5cb98

Browse files
committed
Prefix all sprintf() calls
1 parent f7456b8 commit 6f5cb98

12 files changed

+25
-25
lines changed

Exception/ProcessFailedException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public function __construct(
2727
throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
2828
}
2929

30-
$error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s",
30+
$error = \sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s",
3131
$process->getCommandLine(),
3232
$process->getExitCode(),
3333
$process->getExitCodeText(),
3434
$process->getWorkingDirectory()
3535
);
3636

3737
if (!$process->isOutputDisabled()) {
38-
$error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
38+
$error .= \sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
3939
$process->getOutput(),
4040
$process->getErrorOutput()
4141
);

Exception/ProcessSignaledException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class ProcessSignaledException extends RuntimeException
2323
public function __construct(
2424
private Process $process,
2525
) {
26-
parent::__construct(sprintf('The process has been signaled with signal "%s".', $process->getTermSignal()));
26+
parent::__construct(\sprintf('The process has been signaled with signal "%s".', $process->getTermSignal()));
2727
}
2828

2929
public function getProcess(): Process

Exception/ProcessStartFailedException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(
2626
throw new InvalidArgumentException('Expected a process that failed during startup, but the given process was started successfully.');
2727
}
2828

29-
$error = sprintf('The command "%s" failed.'."\n\nWorking directory: %s\n\nError: %s",
29+
$error = \sprintf('The command "%s" failed.'."\n\nWorking directory: %s\n\nError: %s",
3030
$process->getCommandLine(),
3131
$process->getWorkingDirectory(),
3232
$message ?? 'unknown'

Exception/ProcessTimedOutException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727
private Process $process,
2828
private int $timeoutType,
2929
) {
30-
parent::__construct(sprintf(
30+
parent::__construct(\sprintf(
3131
'The process "%s" exceeded the timeout of %s seconds.',
3232
$process->getCommandLine(),
3333
$this->getExceededTimeout()
@@ -54,7 +54,7 @@ public function getExceededTimeout(): ?float
5454
return match ($this->timeoutType) {
5555
self::TYPE_GENERAL => $this->process->getTimeout(),
5656
self::TYPE_IDLE => $this->process->getIdleTimeout(),
57-
default => throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType)),
57+
default => throw new \LogicException(\sprintf('Unknown timeout type "%d".', $this->timeoutType)),
5858
};
5959
}
6060
}

InputStream.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function write(mixed $input): void
4646
return;
4747
}
4848
if ($this->isClosed()) {
49-
throw new RuntimeException(sprintf('"%s" is closed.', static::class));
49+
throw new RuntimeException(\sprintf('"%s" is closed.', static::class));
5050
}
5151
$this->input[] = ProcessUtils::validateInput(__METHOD__, $input);
5252
}

PhpProcess.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(string $script, ?string $cwd = null, ?array $env = n
5252

5353
public static function fromShellCommandline(string $command, ?string $cwd = null, ?array $env = null, mixed $input = null, ?float $timeout = 60): static
5454
{
55-
throw new LogicException(sprintf('The "%s()" method cannot be called when using "%s".', __METHOD__, self::class));
55+
throw new LogicException(\sprintf('The "%s()" method cannot be called when using "%s".', __METHOD__, self::class));
5656
}
5757

5858
public function start(?callable $callback = null, array $env = []): void

PhpSubprocess.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct(array $command, ?string $cwd = null, ?array $env = n
7575

7676
public static function fromShellCommandline(string $command, ?string $cwd = null, ?array $env = null, mixed $input = null, ?float $timeout = 60): static
7777
{
78-
throw new LogicException(sprintf('The "%s()" method cannot be called when using "%s".', __METHOD__, self::class));
78+
throw new LogicException(\sprintf('The "%s()" method cannot be called when using "%s".', __METHOD__, self::class));
7979
}
8080

8181
public function start(?callable $callback = null, array $env = []): void

Pipes/AbstractPipes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function write(): ?array
101101
} elseif (!isset($this->inputBuffer[0])) {
102102
if (!\is_string($input)) {
103103
if (!\is_scalar($input)) {
104-
throw new InvalidArgumentException(sprintf('"%s" yielded a value of type "%s", but only scalars and stream resources are supported.', get_debug_type($this->input), get_debug_type($input)));
104+
throw new InvalidArgumentException(\sprintf('"%s" yielded a value of type "%s", but only scalars and stream resources are supported.', get_debug_type($this->input), get_debug_type($input)));
105105
}
106106
$input = (string) $input;
107107
}

Pipes/WindowsPipes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(
5252
set_error_handler(function ($type, $msg) use (&$lastError) { $lastError = $msg; });
5353
for ($i = 0;; ++$i) {
5454
foreach ($pipes as $pipe => $name) {
55-
$file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name);
55+
$file = \sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name);
5656

5757
if (!$h = fopen($file.'.lock', 'w')) {
5858
if (file_exists($file.'.lock')) {

Process.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public function start(?callable $callback = null, array $env = []): void
338338
}
339339

340340
if (!is_dir($this->cwd)) {
341-
throw new RuntimeException(sprintf('The provided cwd "%s" does not exist.', $this->cwd));
341+
throw new RuntimeException(\sprintf('The provided cwd "%s" does not exist.', $this->cwd));
342342
}
343343

344344
$lastError = null;
@@ -1215,7 +1215,7 @@ public function setOptions(array $options): void
12151215
foreach ($options as $key => $value) {
12161216
if (!\in_array($key, $existingOptions)) {
12171217
$this->options = $defaultOptions;
1218-
throw new LogicException(sprintf('Invalid option "%s" passed to "%s()". Supported options are "%s".', $key, __METHOD__, implode('", "', $existingOptions)));
1218+
throw new LogicException(\sprintf('Invalid option "%s" passed to "%s()". Supported options are "%s".', $key, __METHOD__, implode('", "', $existingOptions)));
12191219
}
12201220
$this->options[$key] = $value;
12211221
}
@@ -1498,10 +1498,10 @@ private function doSignal(int $signal, bool $throwException): bool
14981498
}
14991499

15001500
if ('\\' === \DIRECTORY_SEPARATOR) {
1501-
exec(sprintf('taskkill /F /T /PID %d 2>&1', $pid), $output, $exitCode);
1501+
exec(\sprintf('taskkill /F /T /PID %d 2>&1', $pid), $output, $exitCode);
15021502
if ($exitCode && $this->isRunning()) {
15031503
if ($throwException) {
1504-
throw new RuntimeException(sprintf('Unable to kill the process (%s).', implode(' ', $output)));
1504+
throw new RuntimeException(\sprintf('Unable to kill the process (%s).', implode(' ', $output)));
15051505
}
15061506

15071507
return false;
@@ -1511,12 +1511,12 @@ private function doSignal(int $signal, bool $throwException): bool
15111511
$ok = @proc_terminate($this->process, $signal);
15121512
} elseif (\function_exists('posix_kill')) {
15131513
$ok = @posix_kill($pid, $signal);
1514-
} elseif ($ok = proc_open(sprintf('kill -%d %d', $signal, $pid), [2 => ['pipe', 'w']], $pipes)) {
1514+
} elseif ($ok = proc_open(\sprintf('kill -%d %d', $signal, $pid), [2 => ['pipe', 'w']], $pipes)) {
15151515
$ok = false === fgets($pipes[2]);
15161516
}
15171517
if (!$ok) {
15181518
if ($throwException) {
1519-
throw new RuntimeException(sprintf('Error while sending signal "%s".', $signal));
1519+
throw new RuntimeException(\sprintf('Error while sending signal "%s".', $signal));
15201520
}
15211521

15221522
return false;
@@ -1595,7 +1595,7 @@ function ($m) use (&$env, $uid) {
15951595
private function requireProcessIsStarted(string $functionName): void
15961596
{
15971597
if (!$this->isStarted()) {
1598-
throw new LogicException(sprintf('Process must be started before calling "%s()".', $functionName));
1598+
throw new LogicException(\sprintf('Process must be started before calling "%s()".', $functionName));
15991599
}
16001600
}
16011601

@@ -1607,7 +1607,7 @@ private function requireProcessIsStarted(string $functionName): void
16071607
private function requireProcessIsTerminated(string $functionName): void
16081608
{
16091609
if (!$this->isTerminated()) {
1610-
throw new LogicException(sprintf('Process must be terminated before calling "%s()".', $functionName));
1610+
throw new LogicException(\sprintf('Process must be terminated before calling "%s()".', $functionName));
16111611
}
16121612
}
16131613

@@ -1637,7 +1637,7 @@ private function replacePlaceholders(string $commandline, array $env): string
16371637
{
16381638
return preg_replace_callback('/"\$\{:([_a-zA-Z]++[_a-zA-Z0-9]*+)\}"/', function ($matches) use ($commandline, $env) {
16391639
if (!isset($env[$matches[1]]) || false === $env[$matches[1]]) {
1640-
throw new InvalidArgumentException(sprintf('Command line is missing a value for parameter "%s": ', $matches[1]).$commandline);
1640+
throw new InvalidArgumentException(\sprintf('Command line is missing a value for parameter "%s": ', $matches[1]).$commandline);
16411641
}
16421642

16431643
return $this->escapeArgument($env[$matches[1]]);

ProcessUtils.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function validateInput(string $caller, mixed $input): mixed
5656
return new \IteratorIterator($input);
5757
}
5858

59-
throw new InvalidArgumentException(sprintf('"%s" only accepts strings, Traversable objects or stream resources.', $caller));
59+
throw new InvalidArgumentException(\sprintf('"%s" only accepts strings, Traversable objects or stream resources.', $caller));
6060
}
6161

6262
return $input;

Tests/ProcessTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function testAllOutputIsActuallyReadOnTermination()
191191
// another byte which will never be read.
192192
$expectedOutputSize = PipesInterface::CHUNK_SIZE * 2 + 2;
193193

194-
$code = sprintf('echo str_repeat(\'*\', %d);', $expectedOutputSize);
194+
$code = \sprintf('echo str_repeat(\'*\', %d);', $expectedOutputSize);
195195
$p = $this->getProcessForCode($code);
196196

197197
$p->start();
@@ -384,7 +384,7 @@ public static function chainedCommandsOutputProvider()
384384
*/
385385
public function testChainedCommandsOutput($expected, $operator, $input)
386386
{
387-
$process = $this->getProcess(sprintf('echo %s %s echo %s', $input, $operator, $input));
387+
$process = $this->getProcess(\sprintf('echo %s %s echo %s', $input, $operator, $input));
388388
$process->run();
389389
$this->assertEquals($expected, $process->getOutput());
390390
}
@@ -992,7 +992,7 @@ public function testMethodsThatNeedARunningProcess($method)
992992
$process = $this->getProcess('foo');
993993

994994
$this->expectException(LogicException::class);
995-
$this->expectExceptionMessage(sprintf('Process must be started before calling "%s()".', $method));
995+
$this->expectExceptionMessage(\sprintf('Process must be started before calling "%s()".', $method));
996996

997997
$process->{$method}();
998998
}
@@ -1492,7 +1492,7 @@ public function testEscapeArgument($arg)
14921492

14931493
public function testRawCommandLine()
14941494
{
1495-
$p = Process::fromShellCommandline(sprintf('"%s" -r %s "a" "" "b"', self::$phpBin, escapeshellarg('print_r($argv);')));
1495+
$p = Process::fromShellCommandline(\sprintf('"%s" -r %s "a" "" "b"', self::$phpBin, escapeshellarg('print_r($argv);')));
14961496
$p->run();
14971497

14981498
$expected = "Array\n(\n [0] => -\n [1] => a\n [2] => \n [3] => b\n)\n";

0 commit comments

Comments
 (0)