diff --git a/app/Cqs/Queries/Products/GetCategoriesProductsQuery.php b/app/Cqs/Queries/Products/GetCategoriesProductsQuery.php index c8c10b65..741f33f8 100644 --- a/app/Cqs/Queries/Products/GetCategoriesProductsQuery.php +++ b/app/Cqs/Queries/Products/GetCategoriesProductsQuery.php @@ -7,7 +7,6 @@ namespace App\Cqs\Queries\Products; use App\Contracts\Directories\ProductDirectory; use App\Contracts\Query; use App\Contracts\QueryInput; -use App\Dto\CategoryProductsDto; use Domain\Models\ValueObjects\Products\ProductCategory; use Webmozart\Assert\Assert; @@ -22,7 +21,7 @@ final readonly class GetCategoriesProductsQuery implements Query } /** - * @return array + * @return array */ public function __invoke(QueryInput $input): array { diff --git a/app/Cqs/Queries/Recipes/GetFrontRecipesQuery.php b/app/Cqs/Queries/Recipes/GetFrontRecipesQuery.php index fb8b9521..763db381 100644 --- a/app/Cqs/Queries/Recipes/GetFrontRecipesQuery.php +++ b/app/Cqs/Queries/Recipes/GetFrontRecipesQuery.php @@ -14,7 +14,11 @@ use Illuminate\Pagination\LengthAwarePaginator; use Webmozart\Assert\Assert; /** + * phpcs:disable Generic.Files.LineLength.TooLong + * * @implements \App\Contracts\Query<\App\Cqs\Queries\Recipes\GetFrontRecipesQueryInput, \Illuminate\Pagination\LengthAwarePaginator> + * + * phpcs:enable */ final readonly class GetFrontRecipesQuery implements Query { diff --git a/app/Http/Requests/Back/Products/UpdateProductRequest.php b/app/Http/Requests/Back/Products/UpdateProductRequest.php index b9b93e29..77630f32 100644 --- a/app/Http/Requests/Back/Products/UpdateProductRequest.php +++ b/app/Http/Requests/Back/Products/UpdateProductRequest.php @@ -26,24 +26,8 @@ class UpdateProductRequest extends StoreProductRequest ]); } - $existingPicture = $product->picture !== null ? new StorageFilePath($product->picture) : null; - $existingPdf = $product->pdf !== null ? new StorageFilePath($product->pdf) : null; - - $picture = null; - if ($this->hasFile('picture')) { - $picture = $this->storeFile($this->file('picture')); - } elseif ($existingPicture !== null) { - $picture = $existingPicture; - } - - $pdf = null; - if ($this->hasFile('pdf')) { - $pdf = $this->storeFile($this->file('pdf')); - } elseif ($this->exists('pdf') && $this->input('pdf') === null) { - $pdf = null; - } elseif ($existingPdf !== null) { - $pdf = $existingPdf; - } + $picture = $this->resolvePicture($product->picture); + $pdf = $this->resolvePdf($product->pdf); return new UpdateProductInput( id: $product->getId(), @@ -109,4 +93,26 @@ class UpdateProductRequest extends StoreProductRequest ], ]); } + + private function resolvePicture(?string $existingPicture): ?StorageFilePath + { + if ($this->hasFile('picture')) { + return $this->storeFile($this->file('picture')); + } + + return $existingPicture !== null ? new StorageFilePath($existingPicture) : null; + } + + private function resolvePdf(?string $existingPdf): ?StorageFilePath + { + if ($this->hasFile('pdf')) { + return $this->storeFile($this->file('pdf')); + } + + if ($this->exists('pdf') && $this->input('pdf') === null) { + return null; + } + + return $existingPdf !== null ? new StorageFilePath($existingPdf) : null; + } }