From 0b929d74de9b42ddc0c3e9ad1cd06ea8473aa3a0 Mon Sep 17 00:00:00 2001 From: Alan Savage <3028205+asavageiv@users.noreply.github.com> Date: Mon, 23 Jun 2025 14:57:34 +0000 Subject: [PATCH] Use guard clause in replaceEnvPlaceholders to reduce indentation Signed-off-by: Alan Savage <3028205+asavageiv@users.noreply.github.com> --- php/src/Docker/DockerActionManager.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index 5e113072..3667294c 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -485,17 +485,18 @@ readonly class DockerActionManager { // escaping. $pattern = '/%([^%]+)%/'; $matchCount = preg_match_all($pattern, $envValue, $matches); - if ($matchCount > 0) { - $placeholders = $matches[0]; // ["%PLACEHOLDER1%", "%PLACEHOLDER2%", ...] - $placeholderNames = $matches[1]; // ["PLACEHOLDER1", "PLACEHOLDER2", ...] - $placeholderToPattern = fn(string $p): string => '/' . $p . '/'; - $placeholderPatterns = array_map($placeholderToPattern, $placeholders); // ["/%PLACEHOLDER1%/", ...] - $placeholderValues = array_map([$this, 'getPlaceholderValue'], $placeholderNames); // ["val1", "val2"] - // Guaranteed to be non-null because we found the placeholders in the preg_match_all. - $result = (string) preg_replace($placeholderPatterns, $placeholderValues, $envValue); - return $result; + + if ($matchCount === 0) { + return $envValue; } - return $envValue; + + $placeholders = $matches[0]; // ["%PLACEHOLDER1%", "%PLACEHOLDER2%", ...] + $placeholderNames = $matches[1]; // ["PLACEHOLDER1", "PLACEHOLDER2", ...] + $placeholderToPattern = fn(string $p): string => '/' . $p . '/'; + $placeholderPatterns = array_map($placeholderToPattern, $placeholders); // ["/%PLACEHOLDER1%/", ...] + $placeholderValues = array_map([$this, 'getPlaceholderValue'], $placeholderNames); // ["val1", "val2"] + // Guaranteed to be non-null because we found the placeholders in the preg_match_all. + return (string) preg_replace($placeholderPatterns, $placeholderValues, $envValue); } private function getPlaceholderValue(string $placeholder) : string {