Improved typing and phpdoc type annotations

This commit is contained in:
Jan Böhmer 2023-06-18 15:37:42 +02:00
parent 3817ba774d
commit b7c8ca2a48
39 changed files with 189 additions and 129 deletions

View file

@ -77,19 +77,20 @@ final class LabelTextReplacer
}
/**
* Replaces all placeholders in the input lines.
* Replaces all placeholders in the input lines.
*
* @param string $lines The input lines that should be replaced
* @param object $target the object that should be used as source for the informations
* @param object $target the object that should be used as source for the information
*
* @return string the Lines with replaced informations
* @return string the Lines with replaced information
*/
public function replace(string $lines, object $target): string
{
$patterns = [
'/(\[\[[A-Z_0-9]+\]\])/' => fn($match) => $this->handlePlaceholder($match[0], $target),
'/(\[\[[A-Z_0-9]+\]\])/' => fn($match): string => $this->handlePlaceholder($match[0], $target),
];
return preg_replace_callback_array($patterns, $lines);
return preg_replace_callback_array($patterns, $lines) ?? throw new \RuntimeException('Could not replace placeholders!');
}
}