ldc-lionor/app/Http/Resources/Fo/Recipes/RecipeResource.php
noah.lancien 8278419606 Phpstan
2024-09-06 08:30:55 +00:00

81 lines
2.3 KiB
PHP

<?php
namespace App\Http\Resources\Fo\Recipes;
use App\Models\Recipe;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class RecipeResource extends JsonResource
{
/** @var \App\Models\Recipe */
private $recipe;
/** @var array */
private static $skeleton = [
'id' => '',
'name' => '',
'slug' => '',
'picture' => '',
'description' => '',
'preparation' => '',
'ingredients' => [],
'portions' => '',
'difficulty' => [
'label' => 'none',
'value' => 0
],
'preparation_time' => '',
'cooking_time' => '',
];
/**
* RecipeResource
*
* @param \App\Models\Recipe $recipe
* @return void
*/
public function __construct(Recipe $recipe)
{
$this->recipe = $recipe;
}
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request|null $request
* @return array
*
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
public function toArray(?Request $request = null): array
{
// phpcs:enable
return array_intersect_key(
[
'id' => $this->recipe->id,
'name' => $this->recipe->name,
'slug' => $this->recipe->slug,
'picture' => $this->recipe->picture,
'description' => $this->recipe->description,
'preparation' => $this->recipe->preparation,
'ingredients' => $this->recipe->ingredients,
'portions' => $this->recipe->portions,
'difficulty' => $this->recipe->difficulty,
'preparation_time' => $this->recipe->preparation_time,
'cooking_time' => $this->recipe->cooking_time,
],
$this->getSkeleton()
);
}
/**
* Returns the resource skeletton
*
* @return array
*/
public static function getSkeleton(): array
{
return self::$skeleton;
}
}