From 35ec3c8bfa791ad8d8d7e6b5f0e053a74edb06d0 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 12 Feb 2021 10:53:07 -0500 Subject: [PATCH] Fix code warnings for 'src/AnimeClient/AnimeClient.php' --- src/AnimeClient/AnimeClient.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/AnimeClient/AnimeClient.php b/src/AnimeClient/AnimeClient.php index 481e34c2..9dd179ba 100644 --- a/src/AnimeClient/AnimeClient.php +++ b/src/AnimeClient/AnimeClient.php @@ -124,7 +124,7 @@ function _iterateToml(TomlBuilder $builder, iterable $data, mixed $parentKey = N /** * Serialize config data into a Toml file * - * @param mixed $data + * @param iterable $data * @return string */ function arrayToToml(iterable $data): string @@ -157,7 +157,7 @@ function tomlToArray(string $toml): array * @param mixed $array * @return bool */ -function isSequentialArray($array): bool +function isSequentialArray(mixed $array): bool { if ( ! is_array($array)) { @@ -270,7 +270,7 @@ function getLocalImg (string $kitsuUrl, $webp = TRUE): string $parts = parse_url($kitsuUrl); - if ($parts === FALSE) + if ($parts === FALSE || ! array_key_exists('path', $parts)) { return 'images/placeholder.webp'; } @@ -296,22 +296,35 @@ function getLocalImg (string $kitsuUrl, $webp = TRUE): string * @param int|null $width * @param int|null $height * @param string $text + * @return bool */ -function createPlaceholderImage (string $path, ?int $width, ?int $height, $text = 'Image Unavailable'): void +function createPlaceholderImage (string $path, ?int $width, ?int $height, $text = 'Image Unavailable'): bool { $width = $width ?? 200; $height = $height ?? 200; $img = imagecreatetruecolor($width, $height); + if ($img === FALSE) + { + return FALSE; + } imagealphablending($img, TRUE); $path = rtrim($path, '/'); // Background is the first color by default $fillColor = imagecolorallocatealpha($img, 255, 255, 255, 127); + if ($fillColor === FALSE) + { + return FALSE; + } imagefill($img, 0, 0, $fillColor); $textColor = imagecolorallocate($img, 64, 64, 64); + if ($textColor === FALSE) + { + return FALSE; + } imagealphablending($img, TRUE); @@ -333,12 +346,18 @@ function createPlaceholderImage (string $path, ?int $width, ?int $height, $text imagedestroy($img); $pngImage = imagecreatefrompng($path . '/placeholder.png'); + if ($pngImage === FALSE) + { + return FALSE; + } imagealphablending($pngImage, TRUE); imagesavealpha($pngImage, TRUE); imagewebp($pngImage, $path . '/placeholder.webp'); imagedestroy($pngImage); + + return TRUE; } /**