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

@ -60,7 +60,9 @@ final class LabelGenerator
}
/**
* @param object|object[] $elements An element or an array of elements for which labels should be generated
* @param object|object[] $elements An element or an array of elements for which labels should be generated
*
* @return null|string
*/
public function generateLabel(LabelOptions $options, object|array $elements): string
{
@ -83,7 +85,7 @@ final class LabelGenerator
$dompdf->loadHtml($this->labelHTMLGenerator->getLabelHTML($options, $elements));
$dompdf->render();
return $dompdf->output();
return $dompdf->output() ?? throw new \RuntimeException('Could not generate label!');
}
/**

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!');
}
}