mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-19 22:16:49 +00:00
Use guard clause in replaceEnvPlaceholders to reduce indentation
Signed-off-by: Alan Savage <3028205+asavageiv@users.noreply.github.com>
This commit is contained in:
parent
0f858dc3fe
commit
0b929d74de
1 changed files with 11 additions and 10 deletions
|
|
@ -485,17 +485,18 @@ readonly class DockerActionManager {
|
||||||
// escaping.
|
// escaping.
|
||||||
$pattern = '/%([^%]+)%/';
|
$pattern = '/%([^%]+)%/';
|
||||||
$matchCount = preg_match_all($pattern, $envValue, $matches);
|
$matchCount = preg_match_all($pattern, $envValue, $matches);
|
||||||
if ($matchCount > 0) {
|
|
||||||
$placeholders = $matches[0]; // ["%PLACEHOLDER1%", "%PLACEHOLDER2%", ...]
|
if ($matchCount === 0) {
|
||||||
$placeholderNames = $matches[1]; // ["PLACEHOLDER1", "PLACEHOLDER2", ...]
|
return $envValue;
|
||||||
$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;
|
|
||||||
|
$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 {
|
private function getPlaceholderValue(string $placeholder) : string {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue