Use guard clause in replaceEnvPlaceholders to reduce indentation

Signed-off-by: Alan Savage <3028205+asavageiv@users.noreply.github.com>
This commit is contained in:
Alan Savage 2025-06-23 14:57:34 +00:00 committed by Simon L.
parent 0f858dc3fe
commit 0b929d74de

View file

@ -485,17 +485,18 @@ readonly class DockerActionManager {
// escaping.
$pattern = '/%([^%]+)%/';
$matchCount = preg_match_all($pattern, $envValue, $matches);
if ($matchCount > 0) {
if ($matchCount === 0) {
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.
$result = (string) preg_replace($placeholderPatterns, $placeholderValues, $envValue);
return $result;
}
return $envValue;
return (string) preg_replace($placeholderPatterns, $placeholderValues, $envValue);
}
private function getPlaceholderValue(string $placeholder) : string {