From: joshuaruesweg Date: Wed, 10 Mar 2021 15:09:14 +0000 (+0100) Subject: Code cleanup X-Git-Tag: 5.4.0_Alpha_1~146^2~10 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=381ec614a81ba8a902e7220e9863bcdba0b5f6af;p=GitHub%2FWoltLab%2FWCF.git Code cleanup --- diff --git a/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_5.4.php b/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_5.4.php index cc9c1a2d4d..2e1bd84ea9 100644 --- a/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_5.4.php +++ b/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_5.4.php @@ -1,7 +1,7 @@ getImageType() == self::IMAGE_COVER && !empty($this->getImageUrl()); + return $this->getImageType() === self::IMAGE_COVER && !empty($this->getImageUrl()); } public function hasSquaredImage(): bool { - return $this->getImageType() == self::IMAGE_SQUARED && !empty($this->getImageUrl()); + return $this->getImageType() === self::IMAGE_SQUARED && !empty($this->getImageUrl()); } private function getImageType(): string @@ -136,7 +136,7 @@ class UnfurlUrl extends DatabaseObject return self::IMAGE_NO_IMAGE; } - if ($this->width == $this->height) { + if ($this->width === $this->height) { return self::IMAGE_SQUARED; } diff --git a/wcfsetup/install/files/lib/system/background/job/UnfurlUrlBackgroundJob.class.php b/wcfsetup/install/files/lib/system/background/job/UnfurlUrlBackgroundJob.class.php index 376ff17b8e..c8f1427c19 100644 --- a/wcfsetup/install/files/lib/system/background/job/UnfurlUrlBackgroundJob.class.php +++ b/wcfsetup/install/files/lib/system/background/job/UnfurlUrlBackgroundJob.class.php @@ -12,6 +12,7 @@ use wcf\system\message\unfurl\exception\UrlInaccessible; use wcf\system\message\unfurl\UnfurlResponse; use wcf\system\WCF; use wcf\util\FileUtil; +use wcf\util\ImageUtil; use wcf\util\StringUtil; use wcf\util\Url; @@ -116,7 +117,7 @@ final class UnfurlUrlBackgroundJob extends AbstractBackgroundJob $imageSaveData = []; if (empty($unfurlResponse->getImageUrl()) || !Url::is($unfurlResponse->getImageUrl())) { - throw new BadMethodCallException("Invalid image given."); + throw new \InvalidArgumentException("The given response does not have an image."); } try { @@ -212,15 +213,13 @@ final class UnfurlUrlBackgroundJob extends AbstractBackgroundJob private function getImageExtension(array $imageData): ?string { - switch ($imageData[2]) { - case \IMAGETYPE_PNG: - return 'png'; - - case \IMAGETYPE_GIF: - return 'gif'; - - case \IMAGETYPE_JPEG: - return 'jpg'; + $extension = ImageUtil::getExtensionByMimeType($imageData['mime']); + switch ($extension) { + case 'gif': + case 'jpg': + case 'png': + case 'webp': + return $extension; default: return null; @@ -241,7 +240,7 @@ final class UnfurlUrlBackgroundJob extends AbstractBackgroundJob break; default: - throw new BadMethodCallException("Invalid status '{$status}' given."); + throw new \InvalidArgumentException("Invalid status '{$status}' given."); } if ($imageID !== null && !empty($imageData)) {