* * @phpcs:enable */ final readonly class FindRecipeQuery implements Query { public function __construct( private PublicS3Disk $publicS3Disk, ) { } #[\Override] public function __invoke(QueryInput $input): ?RecipeDto { Assert::true( $input instanceof FindRecipeByIdInput || $input instanceof FindRecipeBySlugInput, 'Input must be an instance of FindRecipeByIdInput or FindRecipeBySlugInput.' ); $query = Recipe::query(); if ($input->includeTrashed) { $query->withTrashed(); } /** @var Recipe|null $recipe */ $recipe = match (true) { $input instanceof FindRecipeByIdInput => $query->where('id', (string) $input->id)->first(), $input instanceof FindRecipeBySlugInput => $query->where('slug', $input->slug)->first(), }; if ($recipe === null) { return null; } return RecipeDto::fromModel($recipe, $this->publicS3Disk); } }