From 38ac146340aed33a384695425246c4449328bb8b Mon Sep 17 00:00:00 2001 From: philipp lang Date: Tue, 15 Feb 2022 18:15:58 +0100 Subject: [PATCH] Lint --- classes/ImageResizer.php | 17 +++++++++-------- compressors/Compressor.php | 3 +++ compressors/DefaultCompressor.php | 6 ++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/classes/ImageResizer.php b/classes/ImageResizer.php index 9194878..f067bb9 100644 --- a/classes/ImageResizer.php +++ b/classes/ImageResizer.php @@ -2,6 +2,7 @@ namespace Aweos\Resizer\Classes; +use Aweos\Resizer\Compressors\Compressor; use Aweos\Resizer\Exceptions\ResizerException; use Aweos\Resizer\Lib\MediaPath; use Aweos\Resizer\Models\Setting; @@ -17,6 +18,7 @@ class ImageResizer private string $uploadDir; private MediaPath $file; private bool $update; + private Compressor $compressor; public function __construct(FilesystemAdapter $disk, string $uploadDir) { @@ -27,22 +29,23 @@ class ImageResizer public function generate(MediaPath $file, bool $update): void { $this->file = $file; + $this->compressor = $this->file->compressor(); $this->update = $update; if (!$file->exists()) { throw new ResizerException('File versions cannot be generated. Root file "'.$file->root().'" doesnt exist.'); } - if ($this->file->compressor()->shouldGenerateVersions()) { - $this->file->compressor()->start(); + if ($this->compressor->shouldGenerateVersions()) { + $this->compressor->start(); $this->generateVersions(); - $this->file->compressor()->end(); + $this->compressor->end(); } } private function dimensions(): Collection { - [$width, $height] = $this->file->compressor()->originalSize(); + [$width, $height] = $this->compressor->originalSize(); return collect(compact('width', 'height')); } @@ -90,15 +93,13 @@ class ImageResizer private function generateVersions(): void { - $compressor = $this->file->compressor(); - foreach ($this->possibleSizes() as $size) { - $compressor->resize($size, $this->update, function($media, $file) { + $this->compressor->resize($size, $this->update, function($media, $file) { if (!file_exists($file)) { throw new ResizerException('File versions cannot be generated. Version file "'.$file.'" of "'.$this->file->root().'" doesnt exist.'); } if (file_exists($file) || !$this->update) { - $this->file->compressor()->make($file); + $this->compressor->make($file); } }); } diff --git a/compressors/Compressor.php b/compressors/Compressor.php index 7973b67..6522c0b 100644 --- a/compressors/Compressor.php +++ b/compressors/Compressor.php @@ -3,6 +3,7 @@ namespace Aweos\Resizer\Compressors; use Aweos\Resizer\Lib\MediaPath; +use Illuminate\Support\Collection; use Storage; abstract class Compressor @@ -13,8 +14,10 @@ abstract class Compressor abstract function make(string $path): array; abstract protected function getExtension(): string; abstract public function getExtensionRegex(): string; + abstract public function shouldGenerateVersions(): bool; abstract public function start(): void; abstract public function end(): void; + abstract public function resize(Collection $size, bool $update, callable $callback): void; public function __construct(MediaPath $media) { diff --git a/compressors/DefaultCompressor.php b/compressors/DefaultCompressor.php index 1b1864b..d8c1439 100644 --- a/compressors/DefaultCompressor.php +++ b/compressors/DefaultCompressor.php @@ -2,6 +2,8 @@ namespace Aweos\Resizer\Compressors; +use Illuminate\Support\Collection; + class DefaultCompressor extends Compressor { public function getExtension(): string @@ -34,4 +36,8 @@ class DefaultCompressor extends Compressor { // } + public function resize(Collection $size, bool $update, callable $callback): void { + // + } + }