26 lines
585 B
PHP
26 lines
585 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Helpers;
|
||
|
|
||
|
class NutritionCalculator
|
||
|
{
|
||
|
public static function calculateNutritionForRecipe(object $ingredients)
|
||
|
{
|
||
|
$nutrition = [
|
||
|
'kcal' => 0,
|
||
|
'carbohydrates' => 0,
|
||
|
'protein' => 0,
|
||
|
'fat' => 0,
|
||
|
];
|
||
|
|
||
|
foreach($ingredients as $ingredient)
|
||
|
{
|
||
|
foreach(array_keys($nutrition) as $nutritionValue) {
|
||
|
$nutrition[$nutritionValue] += $ingredient['weight'] / 100 * $ingredient['product'][$nutritionValue];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $nutrition;
|
||
|
}
|
||
|
}
|