chore: Проверки к типам

This commit is contained in:
origami11@yandex.ru 2025-12-02 13:16:02 +03:00
parent 8786e84568
commit 18cc1cad01
8 changed files with 34 additions and 28 deletions

View file

@ -18,17 +18,20 @@ class Drawing
* @param int $top
* @param int $width
* @param int $height
* @param list<int> $rgb
* @param list<int<0, 255>> $rgb
*/
static function drawRectangle(GdImage &$image, int $left, int $top, int $width, int $height, array $rgb): void
{
$color = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
if ($color === false) {
throw new \RuntimeException("Can't allocate color");
}
$right = $left + $width;
$bottom = $top + $height;
imageline($image, $left, $top, $right, $top, $color);
imageline($image, $right, $top, $right, $bottom, $color);
imageline($image, $left, $top, $right, $top, $color);
imageline($image, $right, $top, $right, $bottom, $color);
imageline($image, $left, $bottom, $right, $bottom, $color);
imageline($image, $left, $top, $left, $bottom, $color);
imageline($image, $left, $top, $left, $bottom, $color);
}
/**

View file

@ -106,7 +106,11 @@ class TemplateImage
{
$suffix = pathinfo($file, PATHINFO_EXTENSION);
if (array_key_exists($suffix, self::$listfiles)) {
return call_user_func('imagecreatefrom' . self::$listfiles[$suffix], $file);
$imageFn = 'imagecreatefrom' . self::$listfiles[$suffix];
if (!is_callable($imageFn)) {
return null;
}
return call_user_func($imageFn, $file);
}
return null;
}