Mixer now returns a MixedRecipe instead of array

This commit is contained in:
Chris 2019-07-10 23:48:03 +02:00
parent 04f357fc0a
commit efdc860df2
5 changed files with 59 additions and 36 deletions

View File

@ -13,5 +13,8 @@
"psr-4": { "psr-4": {
"NoccyLabs\\Juicer\\": "src/" "NoccyLabs\\Juicer\\": "src/"
} }
},
"require": {
"php": "~7.0"
} }
} }

View File

@ -1,31 +0,0 @@
<?php
namespace NoccyLabs\Juicer\Recipe\Mixer;
use NoccyLabs\Juicer\Ingredient\Base;
use NoccyLabs\Juicer\Recipe\RecipeInterface;
class MeasuredRecipe
{
public function __construct(RecipeInterface $recipe, array $mixedIngredients)
{
}
public function getTotalFlavorMl()
{
}
public function getTotalFlavorPercent()
{
}
public function getTotalFlavorGrams()
{
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace NoccyLabs\Juicer\Recipe\Mixer;
use NoccyLabs\Juicer\Ingredient\Base;
use NoccyLabs\Juicer\Recipe\RecipeInterface;
class MixedRecipe
{
protected $recipe;
protected $mixedIngredients = [];
public function __construct(RecipeInterface $recipe, array $mixedIngredients)
{
$this->recipe = $recipe;
$this->mixedIngredients = $mixedIngredients;
}
public function getIngredients(): array
{
return $this->recipe->getIngredients();
}
public function getMeasuredIngredients(): array
{
return $this->mixedIngredients;
}
public function getTotalFlavorMl(): float
{
}
public function getTotalFlavorPercent(): float
{
}
public function getTotalFlavorGrams(): float
{
}
public function getSpecificGravity(): float
{
}
}

View File

@ -10,7 +10,7 @@ use NoccyLabs\Juicer\Ingredient\NicotineBase;
class Mixer class Mixer
{ {
public function mixRecipe(RecipeInterface $recipe, int $volume, Base $base, int $nicotineStrength, ?NicotineBase $nicotineBase=null) public function mixRecipe(RecipeInterface $recipe, int $volume, Base $base, int $nicotineStrength, ?NicotineBase $nicotineBase=null): MixedRecipe
{ {
// Array holding our final list // Array holding our final list
$mixed = []; $mixed = [];
@ -55,7 +55,8 @@ class Mixer
$mixed[] = new MeasuredIngredient($ingredient, $ingredientPercent, $volume * $floatPercent); $mixed[] = new MeasuredIngredient($ingredient, $ingredientPercent, $volume * $floatPercent);
} }
return $mixed; $mixedRecipe = new MixedRecipe($recipe, $mixed);
return $mixedRecipe;
} }
} }

View File

@ -29,7 +29,7 @@ class MixerTest extends \PhpUnit\Framework\TestCase
$mixer = new Mixer(); $mixer = new Mixer();
$base = new Base($base); $base = new Base($base);
$mixed = $mixer->mixRecipe($recipe, $amount, $base, 0); $mixed = $mixer->mixRecipe($recipe, $amount, $base, 0)->getMeasuredIngredients();
$this->assertCount(count($assertBases), $mixed); $this->assertCount(count($assertBases), $mixed);
$mixedAmount = 0; $mixedAmount = 0;
@ -63,7 +63,7 @@ class MixerTest extends \PhpUnit\Framework\TestCase
{ {
$mixer = new Mixer(); $mixer = new Mixer();
$base = new Base($base); $base = new Base($base);
$mixed = $mixer->mixRecipe($recipe, $amount, $base, 0); $mixed = $mixer->mixRecipe($recipe, $amount, $base, 0)->getMeasuredIngredients();
$expectedCount = count($base->getComponents()) + count($recipe->getIngredients()); $expectedCount = count($base->getComponents()) + count($recipe->getIngredients());