diff --git a/examples/bases.php b/examples/bases.php new file mode 100644 index 0000000..77f8e8f --- /dev/null +++ b/examples/bases.php @@ -0,0 +1,32 @@ +getSpecificGravity()); +} + +echo "\n\n"; + +$asgstrength = [ 24, 20, 18, 15 ]; +$asgheader = join("", array_map(function ($s) { return sprintf("%2dmg ", $s); } , $asgstrength)); + +printf("Apparent Specific Gravity of nicotine bases:\n\n"); +printf(" VG | PG | %s\n", $asgheader); +printf(" ------|------|-------------------------------------\n"); +for ($pg = 0; $pg < 100; $pg += 10) { + printf(" %3d%% | %3d%% |", 100-$pg, $pg); + $base = new Base("PG{$pg}"); + foreach($asgstrength as $s) { + $nicbase = new NicotineBase($base, $s); + printf(" %6.4f ", $nicbase->getSpecificGravity()); + } + printf("\n"); +} diff --git a/src/Recipe/Recipe.php b/src/Recipe/Recipe.php index e7189dc..be44dd5 100644 --- a/src/Recipe/Recipe.php +++ b/src/Recipe/Recipe.php @@ -24,39 +24,59 @@ class Recipe implements RecipeInterface /** @var IngredientInterface[] */ protected $ingredients = []; - public function setRecipeName(?string $name) + public function setRecipeName(?string $name): Recipe { $this->name = $name; + return $this; } - public function setRecipeAuthor(?string $author) + public function setRecipeAuthor(?string $author): Recipe { $this->author = $author; + return $this; } - public function setTags(array $tags) + public function setTags(array $tags): Recipe { $this->tags = $tags; + return $this; } - public function addTag(string $tag) + public function addTag(string $tag): Recipe { $this->tags[] = $tag; + return $this; } - public function setDescription(?string $description) + public function hasTag(string $tag): bool + { + return in_array($tag, $this->tags); + } + + public function removeTag(string $tag): Recipe + { + $this->tags = array_filter($this->tags, function ($input) use ($tag) { + return $input != $tag; + }); + return $this; + } + + public function setDescription(?string $description): Recipe { $this->description = $description; + return $this; } - public function addIngredient(IngredientInterface $ingredient) + public function addIngredient(IngredientInterface $ingredient): Recipe { $this->ingredients[] = $ingredient; + return $this; } - public function setExtra(array $extra) + public function setExtra(array $extra): Recipe { $this->extra = $extra; + return $this; } /** diff --git a/tests/Recipe/RecipeTest.php b/tests/Recipe/RecipeTest.php index 09eb0d9..ddb7ec8 100644 --- a/tests/Recipe/RecipeTest.php +++ b/tests/Recipe/RecipeTest.php @@ -25,4 +25,33 @@ class RecipeTest extends \PhpUnit\Framework\TestCase $this->assertEquals([$ingredient1, $ingredient2], $recipe->getIngredients()); } + public function testManipulatingRecipeTags() + { + $recipe = new Recipe(); + + $recipe + ->addTag("foo") + ->addTag("bar"); + + $this->assertCount(2, $recipe->getTags()); + $this->assertTrue($recipe->hasTag("foo")); + $this->assertTrue($recipe->hasTag("bar")); + $recipe->removeTag("foo"); + $this->assertCount(1, $recipe->getTags()); + $this->assertTrue($recipe->hasTag("bar")); + + $recipe->addTag("baz"); + $this->assertCount(2, $recipe->getTags()); + $this->assertFalse($recipe->hasTag("foo")); + $this->assertTrue($recipe->hasTag("bar")); + $this->assertTrue($recipe->hasTag("baz")); + + $recipe->setTags(["baz"]); + $this->assertCount(1, $recipe->getTags()); + $this->assertFalse($recipe->hasTag("foo")); + $this->assertFalse($recipe->hasTag("bar")); + $this->assertTrue($recipe->hasTag("baz")); + + } + } \ No newline at end of file