diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 829fb07..fcdb5f1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -60,6 +60,31 @@ parameters: count: 1 path: src/ImageStorage.php + - + message: "#^Negated boolean expression is always false\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Offset 1 does not exist on array\\{0\\?\\: string, 1\\?\\: ''\\|numeric\\-string, 2\\?\\: ''\\|numeric\\-string, 3\\?\\: string, 4\\?\\: ''\\|numeric\\-string, 5\\?\\: ''\\|numeric\\-string, 6\\?\\: ''\\|numeric\\-string, 7\\?\\: numeric\\-string\\}\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Offset 1 does not exist on array\\{0\\?\\: string, 1\\?\\: string, 2\\: non\\-falsy\\-string\\}\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Offset 2 does not exist on array\\{0\\?\\: string, 1\\?\\: ''\\|numeric\\-string, 2\\?\\: ''\\|numeric\\-string, 3\\?\\: string, 4\\?\\: ''\\|numeric\\-string, 5\\?\\: ''\\|numeric\\-string, 6\\?\\: ''\\|numeric\\-string, 7\\?\\: numeric\\-string\\}\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Offset 2 does not exist on array\\{0\\?\\: string, 1\\?\\: string, 2\\?\\: non\\-falsy\\-string\\}\\.$#" + count: 1 + path: src/ImageStorage.php + - message: "#^Only booleans are allowed in &&, int given on the right side\\.$#" count: 1 diff --git a/src/ImageNameScript.php b/src/ImageNameScript.php index b375b07..827c040 100644 --- a/src/ImageNameScript.php +++ b/src/ImageNameScript.php @@ -94,6 +94,11 @@ public function setQuality(int $quality): void $this->quality = $quality; } + public function setExtension(string $extension): void + { + $this->extension = $extension; + } + public function getIdentifier(): string { $identifier = implode('/', [$this->namespace, $this->prefix, $this->name]); diff --git a/src/ImageStorage.php b/src/ImageStorage.php index e34e851..d285bdc 100644 --- a/src/ImageStorage.php +++ b/src/ImageStorage.php @@ -208,6 +208,7 @@ public function fromIdentifier(mixed $args): Image $script->setCrop($crop); $script->setFlag($flag); $script->setQuality($quality); + $script->setExtension($args[4] ?? $script->extension); $identifier = $script->getIdentifier(); $data_file = implode('/', [$this->data_path, $identifier]); diff --git a/tests/Cases/ImageNameScriptTest.php b/tests/Cases/ImageNameScriptTest.php index 2c7ba27..2ea2188 100644 --- a/tests/Cases/ImageNameScriptTest.php +++ b/tests/Cases/ImageNameScriptTest.php @@ -48,9 +48,10 @@ public function testFromIdentifier(): void $s->setQuality(2); $s->setSize([2, 2]); $s->setFlag('exact'); + $s->setExtension('png'); - Assert::same($s->getIdentifier(), 'images/49/kitty.2x2.exact.q2.jpg'); - Assert::same($s->toQuery(), 'images/49/2x2.exact.q2/kitty.jpg?_image_storage'); + Assert::same($s->getIdentifier(), 'images/49/kitty.2x2.exact.q2.png'); + Assert::same($s->toQuery(), 'images/49/2x2.exact.q2/kitty.png?_image_storage'); } } diff --git a/tests/Cases/ImageStorageTest.php b/tests/Cases/ImageStorageTest.php index 9eb4df7..7e6c889 100644 --- a/tests/Cases/ImageStorageTest.php +++ b/tests/Cases/ImageStorageTest.php @@ -109,7 +109,7 @@ public function testUpload(): void $upload = new FileUpload([ 'name' => 'upload.jpg', 'type' => 'image/jpg', - 'size' => '20', + 'size' => 20, 'tmp_name' => $tempImagePath, 'error' => 0, ]);