<?php
/**
- * Makes non-critical database adjustments (i.e. everything that is not related
+ * Makes non-critical database adjustments (i.e. everything that is not related
* to sessions).
*
* @author Tim Duesterhus
public function hasCoverImage(): bool
{
- return $this->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
return self::IMAGE_NO_IMAGE;
}
- if ($this->width == $this->height) {
+ if ($this->width === $this->height) {
return self::IMAGE_SQUARED;
}
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;
$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 {
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;
break;
default:
- throw new BadMethodCallException("Invalid status '{$status}' given.");
+ throw new \InvalidArgumentException("Invalid status '{$status}' given.");
}
if ($imageID !== null && !empty($imageData)) {