Fix code warnings for 'src/AnimeClient/AnimeClient.php'
This commit is contained in:
parent
52a0ff275d
commit
35ec3c8bfa
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user