Improved MixedRecipe

This commit is contained in:
2019-07-11 00:19:45 +02:00
parent 6cffe68da5
commit 796bd626c9
3 changed files with 105 additions and 7 deletions

View File

@ -7,15 +7,41 @@ use NoccyLabs\Juicer\Recipe\RecipeInterface;
class MixedRecipe
{
/** @var RecipeInterface The recipe that was mixed */
protected $recipe;
protected $mixedIngredients = [];
public function __construct(RecipeInterface $recipe, array $mixedIngredients)
protected $base;
protected $volume;
protected $nicotine;
protected $totalFlavorMl;
protected $totalFlavorPercent;
protected $totalFlavorGrams;
protected $specificGravity;
public function __construct(RecipeInterface $recipe, array $mixedIngredients, Base $base, int $volume, int $nicotine)
{
$this->recipe = $recipe;
$this->mixedIngredients = $mixedIngredients;
$this->base = $base;
$this->volume = $volume;
$this->nicotine = $nicotine;
foreach ($mixedIngredients as $mixedIngredient) {
if (!in_array($mixedIngredient->getFlavorName(), ['PG','VG'])) {
$this->totalFlavorMl += $mixedIngredient->getVolume();
$this->totalFlavorGrams += $mixedIngredient->getWeight();
$this->totalFlavorPercent += $mixedIngredient->getPercent();
}
$this->specificGravity += $mixedIngredient->getSpecificGravity() * ($mixedIngredient->getPercent() / 100);
}
}
public function getIngredients(): array
@ -23,6 +49,16 @@ class MixedRecipe
return $this->recipe->getIngredients();
}
public function getBase(): Base
{
return $this->base;
}
public function getVolume(): int
{
return $this->volume;
}
public function getMeasuredIngredients(): array
{
return $this->mixedIngredients;
@ -30,21 +66,21 @@ class MixedRecipe
public function getTotalFlavorMl(): float
{
return $this->totalFlavorMl;
}
public function getTotalFlavorPercent(): float
{
return $this->totalFlavorPercent;
}
public function getTotalFlavorGrams(): float
{
return $this->totalFlavorGrams;
}
public function getSpecificGravity(): float
{
return $this->specificGravity;
}
}

View File

@ -55,7 +55,7 @@ class Mixer
$mixed[] = new MeasuredIngredient($ingredient, $ingredientPercent, $volume * $floatPercent);
}
$mixedRecipe = new MixedRecipe($recipe, $mixed);
$mixedRecipe = new MixedRecipe($recipe, $mixed, $base, $volume, $nicotineStrength);
return $mixedRecipe;
}