119 lines
4 KiB
PHP
119 lines
4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Domain\Models\ValueObjects;
|
|
|
|
final readonly class NutritionalValues
|
|
{
|
|
public function __construct(
|
|
// * Base
|
|
public ?float $refWeightG = null,
|
|
// * Pour 100g ou par référence
|
|
public ?float $kj = null,
|
|
public ?float $kcal = null,
|
|
public ?float $fatG = null,
|
|
public ?float $satFatG = null,
|
|
public ?float $carbG = null,
|
|
public ?float $sugarG = null,
|
|
public ?float $fiberG = null,
|
|
public ?float $proteinG = null,
|
|
public ?float $saltG = null,
|
|
// * Par portion
|
|
public ?float $servingSizeG = null,
|
|
public ?float $servingKj = null,
|
|
public ?float $servingKcal = null,
|
|
public ?float $servingFatG = null,
|
|
public ?float $servingSatFatG = null,
|
|
public ?float $servingCarbG = null,
|
|
public ?float $servingSugarG = null,
|
|
public ?float $servingFiberG = null,
|
|
public ?float $servingProteinG = null,
|
|
public ?float $servingSaltG = null,
|
|
// * Apports journaliers (% AR)
|
|
public ?float $dailyEnergy = null,
|
|
public ?float $dailyFat = null,
|
|
public ?float $dailySatFat = null,
|
|
public ?float $dailyCarb = null,
|
|
public ?float $dailySugar = null,
|
|
public ?float $dailyFiber = null,
|
|
public ?float $dailyProtein = null,
|
|
public ?float $dailySalt = null,
|
|
) {
|
|
$values = [
|
|
$refWeightG,
|
|
$kj,
|
|
$kcal,
|
|
$fatG,
|
|
$satFatG,
|
|
$carbG,
|
|
$sugarG,
|
|
$fiberG,
|
|
$proteinG,
|
|
$saltG,
|
|
$servingSizeG,
|
|
$servingKj,
|
|
$servingKcal,
|
|
$servingFatG,
|
|
$servingSatFatG,
|
|
$servingCarbG,
|
|
$servingSugarG,
|
|
$servingFiberG,
|
|
$servingProteinG,
|
|
$servingSaltG,
|
|
$dailyEnergy,
|
|
$dailyFat,
|
|
$dailySatFat,
|
|
$dailyCarb,
|
|
$dailySugar,
|
|
$dailyFiber,
|
|
$dailyProtein,
|
|
$dailySalt,
|
|
];
|
|
|
|
foreach ($values as $val) {
|
|
if ($val !== null && $val < 0) {
|
|
throw new \DomainException('Nutritional values cannot be negative');
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array<string,float|null>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'nv_ref_weight_g' => $this->refWeightG,
|
|
'nv_kj' => $this->kj,
|
|
'nv_kcal' => $this->kcal,
|
|
'nv_fat_g' => $this->fatG,
|
|
'nv_sat_fat_g' => $this->satFatG,
|
|
'nv_carb_g' => $this->carbG,
|
|
'nv_sugar_g' => $this->sugarG,
|
|
'nv_fiber_g' => $this->fiberG,
|
|
'nv_protein_g' => $this->proteinG,
|
|
'nv_salt_g' => $this->saltG,
|
|
|
|
'nv_serving_size_g' => $this->servingSizeG,
|
|
'nv_serving_kj' => $this->servingKj,
|
|
'nv_serving_kcal' => $this->servingKcal,
|
|
'nv_serving_fat_g' => $this->servingFatG,
|
|
'nv_serving_sat_fat_g' => $this->servingSatFatG,
|
|
'nv_serving_carb_g' => $this->servingCarbG,
|
|
'nv_serving_sugar_g' => $this->servingSugarG,
|
|
'nv_serving_fiber_g' => $this->servingFiberG,
|
|
'nv_serving_protein_g' => $this->servingProteinG,
|
|
'nv_serving_salt_g' => $this->servingSaltG,
|
|
|
|
'nv_daily_energy' => $this->dailyEnergy,
|
|
'nv_daily_fat' => $this->dailyFat,
|
|
'nv_daily_sat_fat' => $this->dailySatFat,
|
|
'nv_daily_carb' => $this->dailyCarb,
|
|
'nv_daily_sugar' => $this->dailySugar,
|
|
'nv_daily_fiber' => $this->dailyFiber,
|
|
'nv_daily_protein' => $this->dailyProtein,
|
|
'nv_daily_salt' => $this->dailySalt,
|
|
];
|
|
}
|
|
}
|