mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-27 04:08:57 +02:00
Improved typing and phpdoc type annotations
This commit is contained in:
parent
3817ba774d
commit
b7c8ca2a48
39 changed files with 189 additions and 129 deletions
|
@ -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!');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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!');
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue