Skip to content

Commit

Permalink
fix php 8.2 string interpolation warnings
Browse files Browse the repository at this point in the history
Using ${var} in strings is deprecated, use {$var} instead [1]

[1]: https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation
  • Loading branch information
ktomk committed Aug 7, 2023
1 parent 4eb514e commit 0812168
Show file tree
Hide file tree
Showing 27 changed files with 50 additions and 47 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ The format is based on [Keep a Changelog] and Pipelines adheres to
### Add
- PHP 8.2 Alpine based build container
### Fix
- PHP 8.2 Using ${var} in strings deprecations (#24) (thanks
[Brad Kent][Brad Kent])
- Eager substr_replace() use in updateTimestamps() (thanks [Jan Tvrdík])
- Fix type annotation and add support for DateTimeImmutable (thanks
[Jordi Boggiano])

[Brad Kent]: https://github.com/bkdotcom
[Jan Tvrdík]: https://github.com/JanTvrdik
[Jordi Boggiano]: https://github.com/Seldaek

Expand Down
2 changes: 1 addition & 1 deletion lib/build/coverage-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
$fMetrics = function ($s) use ($xml) {
return array_sum(array_map(
'intval',
$xml->xpath(".//metrics/@${s}elements")
$xml->xpath(".//metrics/@{$s}elements")
));
};

Expand Down
4 changes: 2 additions & 2 deletions src/Cli/Docker/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function findAllContainerIdsByName($name)
'docker',
array(
'ps', '--no-trunc', '-qa', '--filter',
"name=^/\\Q${name}\\E$",
"name=^/\\Q{$name}\\E$",
),
$result
);
Expand Down Expand Up @@ -150,7 +150,7 @@ private function psPrefixImpl($prefix, $all = false)
'docker',
array(
'ps', '-q' . ($all ? 'a' : ''), '--no-trunc', '--filter',
"name=^/${prefix}[-.]",
"name=^/{$prefix}[-.]",
),
$result
);
Expand Down
4 changes: 2 additions & 2 deletions src/Cli/Exec.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function pass($command, array $arguments)
}

':' === $buffer ? $status = 0 : passthru($buffer, $status);
$this->debug("exit status: ${status}");
$this->debug("exit status: {$status}");

return $status;
}
Expand Down Expand Up @@ -80,7 +80,7 @@ public function capture($command, array $arguments, &$out = null, &$err = null)

$proc = new Proc($buffer);
$status = $proc->run();
$this->debug("exit status: ${status}");
$this->debug("exit status: {$status}");
$out = $proc->getStandardOutput();
$err = $proc->getStandardError();

Expand Down
6 changes: 3 additions & 3 deletions src/File/Definitions/Caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ private function parse(array $array)
{
foreach ($array as $name => $path) {
if (!is_string($name)) {
throw new ParseException("cache definition invalid cache name: ${name}");
throw new ParseException("cache definition invalid cache name: {$name}");
}

if (null === $path) {
throw new ParseException("cache '${name}' should be a string value (it is currently null or empty)");
throw new ParseException("cache '{$name}' should be a string value (it is currently null or empty)");
}

if (is_bool($path)) {
throw new ParseException("cache '${name}' should be a string (it is currently defined as a boolean)");
throw new ParseException("cache '{$name}' should be a string (it is currently defined as a boolean)");
}

// Fixme(tk): more importantly is that $path is not array or object
Expand Down
4 changes: 2 additions & 2 deletions src/File/Definitions/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ private function parseVariables(array $array)

foreach ($variables as $name => $value) {
if (null === $value) {
throw new ParseException("variable ${name} should be a string value (it is currently null or empty)");
throw new ParseException("variable {$name} should be a string value (it is currently null or empty)");
}
if (is_bool($value)) {
throw new ParseException("variable ${name} should be a string (it is currently defined as a boolean)");
throw new ParseException("variable {$name} should be a string (it is currently defined as a boolean)");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/File/Pipeline/StepParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function parseAfterScript(array $step)
private function parseNamedScript($name, array $script)
{
if (!is_array($script[$name]) || !count($script[$name])) {
throw new ParseException("'${name}' requires a list of commands");
throw new ParseException("'{$name}' requires a list of commands");
}

foreach ($script[$name] as $index => $line) {
Expand Down
8 changes: 4 additions & 4 deletions src/File/Pipelines.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private function parseValidatePipelines(array $array)
if (!$count && !isset($array['default'])) {
$middle = implode(', ', array_slice($sections, 0, -1));

throw new ParseException("'pipelines' requires at least a default, ${middle} or custom section");
throw new ParseException("'pipelines' requires at least a default, {$middle} or custom section");
}
}

Expand All @@ -259,7 +259,7 @@ private function referencesDefault(array &$array)
}

if (!is_array($array[$default])) {
throw new ParseException("'${default}' requires a list of steps");
throw new ParseException("'{$default}' requires a list of steps");
}

$references[$default] = array($default, null, &$array[$default]);
Expand All @@ -285,10 +285,10 @@ private function referencesAddSections(array $references, array &$array)
continue; // not a section for references
}
if (!is_array($refs)) {
throw new ParseException("'${section}' requires a list");
throw new ParseException("'{$section}' requires a list");
}
foreach ($refs as $pattern => $pipeline) {
$references["${section}/${pattern}"] = array(
$references["{$section}/{$pattern}"] = array(
(string)$section,
(string)$pattern,
&$array[$section][$pattern],
Expand Down
4 changes: 2 additions & 2 deletions src/File/PipelinesReferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static function idNonPatternMatch(Pipelines $pipelines, $section, $refer

# check for direct (non-pattern) match
if (isset($pipelines->array[$section][$reference])) {
return array(true, "${section}/${reference}");
return array(true, "{$section}/{$reference}");
}

return array(false, null);
Expand Down Expand Up @@ -158,6 +158,6 @@ private static function idPattern(Pipelines $pipelines, $section, $reference)
}
}

return array('' !== $match, "${section}/${match}");
return array('' !== $match, "{$section}/{$match}");
}
}
2 changes: 1 addition & 1 deletion src/Lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function quoteArg($argument)
foreach ($parts as $index => $part) {
$index && $buffer .= "\\'";
$safe = preg_match('~^[a-zA-Z0-9,._+@%/-]*$~D', $part);
$buffer .= $safe ? $part : "'${part}'";
$buffer .= $safe ? $part : "'{$part}'";
}

if ('' === $buffer) {
Expand Down
2 changes: 1 addition & 1 deletion src/LibFs.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static function rmDir($dir)
throw new UnexpectedValueException(sprintf('Failed to open directory: %s', $current));
}
foreach (array_diff($result, array('.', '..')) as $file) {
$path = "${current}/${file}";
$path = "{$current}/{$file}";
if (is_link($path)) {
self::unlink($path);
} elseif (is_dir($path)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Containers/StepServiceContainers.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function shutdown($status)
Containers::execShutdownContainer(
$this->runner->getExec(),
$this->runner->getStreams(),
"/${name}",
"/{$name}",
$status,
$this->runner->getFlags(),
sprintf('keeping service container %s', $name)
Expand Down
6 changes: 3 additions & 3 deletions src/Runner/Docker/Provision/TarCopier.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function extMakeEmptyDirectory(Exec $exec, $id, $source, $target)
}

if (!is_dir($source)) {
throw new \InvalidArgumentException("not a directory: '${source}'");
throw new \InvalidArgumentException("not a directory: '{$source}'");
}

$tmpDir = DestructibleString::rmDir(LibTmp::tmpDir('pipelines-cp.'));
Expand All @@ -60,7 +60,7 @@ public static function extMakeEmptyDirectory(Exec $exec, $id, $source, $target)
$tar = Lib::cmd('tar', array('c', '-h', '-f', '-', '--no-recursion', '.' . $target));
$dockerCp = Lib::cmd('docker ', array('cp', '-', $id . ':/.'));

return $exec->pass("${cd} && ${tar} | ${dockerCp}", array());
return $exec->pass("{$cd} && {$tar} | {$dockerCp}", array());
}

/**
Expand Down Expand Up @@ -91,7 +91,7 @@ public static function extCopyDirectory(Exec $exec, $id, $source, $target)
$tar = Lib::cmd('tar', array('c', '-f', '-', '.'));
$dockerCp = Lib::cmd('docker ', array('cp', '-', $id . ':' . $target));

return $exec->pass("${cd} && ${tar} | ${dockerCp}", array());
return $exec->pass("{$cd} && {$tar} | {$dockerCp}", array());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Runner/StepRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public function runStep(Step $step)
if (null === $id) {
$streams->out(" container-id...: *failure*\n\n");
$streams->err("pipelines: setting up the container failed\n");
empty($err) || $streams->err("${err}\n");
empty($out) || $streams->out("${out}\n");
empty($err) || $streams->err("{$err}\n");
empty($out) || $streams->out("{$out}\n");
$streams->out(sprintf("exit status: %d\n", $status));

return $status;
Expand Down Expand Up @@ -377,7 +377,7 @@ private function obtainWorkingDirMount($copy, $dir, array $mountDockerSock)
if ($checkMount && $clonePath === $dir && null === $hostDeviceDir) {
$deviceDir = $this->runner->getEnv()->getValue('PIPELINES_PROJECT_PATH');
if ($deviceDir === $dir || null === $deviceDir) {
$this->runner->getStreams()->err("pipelines: fatal: can not detect ${dir} mount point\n");
$this->runner->getStreams()->err("pipelines: fatal: can not detect {$dir} mount point\n");

return array(null, 1);
}
Expand All @@ -386,7 +386,7 @@ private function obtainWorkingDirMount($copy, $dir, array $mountDockerSock)
// FIXME(tk): Never mount anything not matching /home/[a-zA-Z][a-zA-Z0-9]*/[^.].*/...
// + do realpath checking
// + prevent dot path injections (logical fix first)
return array('-v', "${deviceDir}:${clonePath}");
return array('-v', "{$deviceDir}:{$clonePath}");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/StepScriptRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function runStepScript(Step $step)
if ($this->runner->getRunOpts()->getBoolOption('script.bash-runner')) {
$bashRunner = '/bin/bash';
0 === $exec->capture('docker', array(
'exec', $name, '/bin/sh', '-c', "test -f ${bashRunner} && test -x ${bashRunner}",
'exec', $name, '/bin/sh', '-c', "test -f {$bashRunner} && test -x {$bashRunner}",
)) && $scriptRunner = $bashRunner;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Runner/StepScriptWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static function generateCommand($line)
foreach ($line['variables'] as $name => $value) {
$buffer .= sprintf(
"printf %%s %s; printf '%%s ' %s; printf '\\n' \n",
Lib::quoteArg(" ${name} (${value}): "),
Lib::quoteArg(" {$name} ({$value}): "),
$value
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/DockerOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private function runPs()
'docker ps -a',
array(
'--filter',
"name=^/${prefix}[-.]",
"name=^/{$prefix}[-.]",
)
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Utility/RunnerOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private function parseUser(Args $args)
sprintf(
'--user internal error to resolve id -u / id -g: %d%s',
$status,
$err ? " : ${err}" : ''
$err ? " : {$err}" : ''
)
);
}
Expand All @@ -185,7 +185,7 @@ private function parseDockerClient(Args $args)
$repository->resolve($binaryClient);
} catch (\InvalidArgumentException $ex) {
$message = '--docker-client needs a valid package name, file or docker client binary path;';
$message .= " '${binaryClient}' given";
$message .= " '{$binaryClient}' given";
$message .= "\n docker client binary packages shipping w/ pipelines:";
$message .= "\n - " . implode("\n - ", $repository->listPackages());

Expand Down
4 changes: 2 additions & 2 deletions src/Utility/Show/FileShower.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private function getAllSteps(File $file)
$return = array();
foreach ($file->getPipelines()->getPipelines() as $id => $pipeline) {
foreach (Steps::fullIter($pipeline->getSteps()) as $index => $step) {
$return["${id}:/step/${index}"] = $step;
$return["{$id}:/step/{$index}"] = $step;
}
}

Expand All @@ -235,7 +235,7 @@ private function getAllStepsWithServices(File $file)
foreach ($this->getAllSteps($file) as $key => $step) {
$return[$key] = $step;
foreach ($step->getServices()->getDefinitions() as $name => $service) {
$return["${key}/service/${name}"] = $service;
$return["{$key}/service/{$name}"] = $service;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/File/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function provideCommands()
*/
public function testSuccessfulCommands($command)
{
$this->assert("bin/pipelines --file test/data/yml/images.yml ${command}");
$this->assert("bin/pipelines --file test/data/yml/images.yml {$command}");
}

private function assert($command)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/InvocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function provideCommands()
*/
public function testSuccessfulCommands($command)
{
$this->assert("bin/pipelines ${command}");
$this->assert("bin/pipelines {$command}");
}

private function assert($command)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/Runner/Docker/Binary/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testInjection()
$containerId = '424242-so-long-and-thanks-for-all-the-fish';
list($status, $message) = $repository->inject($containerId);
self::assertSame(1, $status);
self::assertMatchesRegularExpression("~${containerId}~", $message);
self::assertMatchesRegularExpression("~{$containerId}~", $message);
$this->addToAssertionCount(1);
}

Expand Down
8 changes: 4 additions & 4 deletions test/unit/Cli/ExecTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private function expectMessages()
$context,
$message
) = $current;
$messages[] = sprintf('%s: %s%s', $expectedMethod, $expectedCommand, $message ? " // ${message}" : '');
$messages[] = sprintf('%s: %s%s', $expectedMethod, $expectedCommand, $message ? " // {$message}" : '');
}

return $messages;
Expand Down Expand Up @@ -207,20 +207,20 @@ private function dealInvokeExpectation($method, $command, array $arguments, &$ou
$testCase::assertSame(
$expectedMethod,
$method,
sprintf("Method on exec mismatch with command '%s'%s", $command, $message ? " // ${message}" : '')
sprintf("Method on exec mismatch with command '%s'%s", $command, $message ? " // {$message}" : '')
);

if ('' !== $expectedCommand && '~' === $expectedCommand[0]) {
$testCase::assertMatchesRegularExpression(
$expectedCommand,
$command,
sprintf("Command on exec mismatch with method '%s'%s", $method, $message ? " // ${message}" : '')
sprintf("Command on exec mismatch with method '%s'%s", $method, $message ? " // {$message}" : '')
);
} else {
$testCase::assertSame(
$expectedCommand,
$command,
sprintf("Command on exec mismatch with method '%s'%s", $method, $message ? " // ${message}" : '')
sprintf("Command on exec mismatch with method '%s'%s", $method, $message ? " // {$message}" : '')
);
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/File/Pipeline/StepConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testUsageExample()
foreach ($file->getPipelines()->getPipelines() as $id => $pipeline) {
foreach ($pipeline->getSteps() as $index => $step) {
$condition = $step->getCondition();
self::assertNotNull($condition, "${id}: #${index}");
self::assertNotNull($condition, "{$id}: #{$index}");
self::assertNotEmpty($condition->getIncludePaths());
$actual++;
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/LibFsPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function provideAbsolutePaths()
public function testIsAbsolute($path, $expected)
{
$actual = LibFsPath::isAbsolute($path);
self::assertSame($expected, $actual, "path '${path}' is (not) absolute");
self::assertSame($expected, $actual, "path '{$path}' is (not) absolute");
}

public function provideBasenamePaths()
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Utility/Show/FileShowerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function provideFileForMethod()
*/
public function testShowFileByMethod($path, $method, $expected, $parseExceptionMessage = null)
{
self::assertTrue(method_exists(__NAMESPACE__ . '\FileShower', $method), "FileShower::${method}()");
self::assertTrue(method_exists(__NAMESPACE__ . '\FileShower', $method), "FileShower::{$method}()");
$file = File::createFromFile($path);
$shower = new FileShower(new Streams(), $file);

Expand Down Expand Up @@ -178,7 +178,7 @@ public function provideHappyFilesForShowFileMethod()
*/
public function testShowFileByMethodHappyOutput($path, $method, $expected)
{
self::assertTrue(method_exists(__NAMESPACE__ . '\FileShower', $method), "FileShower::${method}()");
self::assertTrue(method_exists(__NAMESPACE__ . '\FileShower', $method), "FileShower::{$method}()");
$expected = rtrim($expected) . "\n";

list($outHandle) = LibTmp::tmpFile();
Expand Down
Loading

0 comments on commit 0812168

Please sign in to comment.