diff --git a/src/Handler/FileEraser.php b/src/Handler/FileEraser.php index b538c88..1e59578 100644 --- a/src/Handler/FileEraser.php +++ b/src/Handler/FileEraser.php @@ -25,11 +25,32 @@ public function remove(string $fileName): bool $result = unlink($fullFilePath); } - return $result; + $result = $result && $this->removeWebpFile($fileName); + + return $result && $this->removeAvifFile($fileName); + } + + private function removeWebpFile(string $fileName): bool + { + $webpFileName = pathinfo($fileName, PATHINFO_FILENAME) . '.webp'; + $fullFilePath = $this->imagesDir . $webpFileName; + + if (file_exists($fullFilePath)) { + return unlink($fullFilePath); + } + + return true; } - public function getTargetDirectory() + private function removeAvifFile(string $fileName): bool { - return $this->imagesDir; + $avifFileName = pathinfo($fileName, PATHINFO_FILENAME) . '.avif'; + $fullFilePath = $this->imagesDir . $avifFileName; + + if (file_exists($fullFilePath)) { + return unlink($fullFilePath); + } + + return true; } }