diff --git a/php7/src/AgedBried.php b/php7/src/AgedBrie.php similarity index 92% rename from php7/src/AgedBried.php rename to php7/src/AgedBrie.php index abfe684a..46073c5f 100644 --- a/php7/src/AgedBried.php +++ b/php7/src/AgedBrie.php @@ -4,7 +4,7 @@ namespace App; -class AgedBried extends GildedRose +class AgedBrie extends GildedRose { private $item; diff --git a/php7/src/Conjured.php b/php7/src/Conjured.php new file mode 100644 index 00000000..965a85f8 --- /dev/null +++ b/php7/src/Conjured.php @@ -0,0 +1,23 @@ +item = $item; + } + public function updateQuality(){ + $this->item->quality -= 2; + + if ($this->item->sell_in <= 0) { + $this->item->quality -= 2; + } + + $this->item->sell_in -= 1; + } +} \ No newline at end of file diff --git a/php7/src/DefaultItem.php b/php7/src/DefaultItem.php index d5d4507d..f932fdb2 100644 --- a/php7/src/DefaultItem.php +++ b/php7/src/DefaultItem.php @@ -13,9 +13,15 @@ class DefaultItem extends GildedRose } public function updateQuality(){ $this->item->quality -= 1; + if ($this->item->sell_in <= 0) { $this->item->quality -= 1; } + + if($this->item->quality >= 50){ + $this->item->quality = 50; + } + $this->item->sell_in -= 1; } diff --git a/php7/src/GildedRose.php b/php7/src/GildedRose.php index 3f9e9445..2377c0d7 100644 --- a/php7/src/GildedRose.php +++ b/php7/src/GildedRose.php @@ -17,27 +17,33 @@ class GildedRose $agedBrieName = 'Aged Brie'; $backstageName = 'Backstage passes to a TAFKAL80ETC concert'; $sulfarasName = 'Sulfuras, Hand of Ragnaros'; + $conjuredName = 'Conjured Mana Cake'; foreach ($this->items as $item) { switch ($item->name) { + case $conjuredName: + $conjured = new Conjured($item); + $conjured->updateQuality(); + break; + case $agedBrieName: - $agedBried = new AgedBried($item); + $agedBried = new AgedBrie($item); $agedBried->updateQuality(); - return; + break; case $backstageName: $backstagePasses = new BackstagePasses($item); $backstagePasses->updateQuality(); - return; + break; case $sulfarasName: $sulfaras = new Sulfaras($item); $sulfaras->updateQuality(); - return; + break; default: $defoultItem = new DefaultItem($item); $defoultItem->updateQuality(); - return; + break; } } } diff --git a/php7/test/GildedRoseTest.php b/php7/test/GildedRoseTest.php index 52367c20..dd5330ff 100644 --- a/php7/test/GildedRoseTest.php +++ b/php7/test/GildedRoseTest.php @@ -5,7 +5,7 @@ namespace App; class GildedRoseTest extends \PHPUnit\Framework\TestCase { - public function test_random_item_than_quality_maximum() + public function test_random_item_then_quality_maximum() { $items = [new Item("Random item", 1, 50)]; $gildedRose = new GildedRose($items); @@ -14,7 +14,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 0); } - public function test_random_item_than_sell_in_is_0_or_lower() + public function test_random_item_then_sell_in_is_0_or_lower() { $items = [new Item("Random item", 0, 3)]; $gildedRose = new GildedRose($items); @@ -23,7 +23,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, -1); } - public function test_random_item_than_sell_in_greater_then_0() + public function test_random_item_then_sell_in_greater_then_0() { $items = [new Item("Random item", 1, 3)]; $gildedRose = new GildedRose($items); @@ -32,7 +32,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 0); } - public function test_backstage_than_quality_maximum_sell_in_lower_then_zero() + public function test_backstage_then_quality_maximum_sell_in_lower_then_zero() { $items = [new Item("Backstage passes to a TAFKAL80ETC concert", -5, 50)]; $gildedRose = new GildedRose($items); @@ -41,7 +41,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, -6); } - public function test_backstage_than_quality_maximum_sell_in_beetween_one_and_five() + public function test_backstage_then_quality_maximum_sell_in_beetween_one_and_five() { $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 1, 50)]; $gildedRose = new GildedRose($items); @@ -50,7 +50,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 0); } - public function test_backstage_than_quality_maximum_sell_in_beetween_five_and_ten() + public function test_backstage_then_quality_maximum_sell_in_beetween_five_and_ten() { $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 7, 50)]; $gildedRose = new GildedRose($items); @@ -59,7 +59,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 6); } - public function test_backstage_than_quality_maximum_sell_in_greater_then_ten() + public function test_backstage_then_quality_maximum_sell_in_greater_then_ten() { $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 11, 50)]; $gildedRose = new GildedRose($items); @@ -68,7 +68,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 10); } - public function test_backstage_than_sell_in_greater_then_ten() + public function test_backstage_then_sell_in_greater_then_ten() { $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 11, 1)]; $gildedRose = new GildedRose($items); @@ -77,7 +77,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 10); } - public function test_backstage_than_sell_in_beetween_five_and_ten() + public function test_backstage_then_sell_in_beetween_five_and_ten() { $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 7, 1)]; $gildedRose = new GildedRose($items); @@ -86,7 +86,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 6); } - public function test_backstage_than_beetween_one_and_five() + public function test_backstage_then_beetween_one_and_five() { $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 5, 1)]; $gildedRose = new GildedRose($items); @@ -95,7 +95,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 4); } - public function test_backstage_than_sell_in_is_zero() + public function test_backstage_then_sell_in_is_zero() { $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 0, 1)]; $gildedRose = new GildedRose($items); @@ -104,7 +104,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, -1); } - public function test_sulfuras_than_sell_in_greater_then_zero() + public function test_sulfuras_then_sell_in_greater_then_zero() { $items = [new Item("Sulfuras, Hand of Ragnaros", 1, 1)]; $gildedRose = new GildedRose($items); @@ -113,7 +113,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 1); } - public function test_sulfuras_than_sell_in_zero() + public function test_sulfuras_then_sell_in_zero() { $items = [new Item("Sulfuras, Hand of Ragnaros", 0, 1)]; $gildedRose = new GildedRose($items); @@ -122,7 +122,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 0); } - public function test_sulfuras_than_sell_in_lower_then_zero() + public function test_sulfuras_then_sell_in_lower_then_zero() { $items = [new Item("Sulfuras, Hand of Ragnaros", -1, 10)]; $gildedRose = new GildedRose($items); @@ -131,7 +131,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, -1); } - public function test_aged_brie_than_sell_in_greater_then_zero() + public function test_aged_brie_then_sell_in_greater_then_zero() { $items = [new Item("Aged Brie", 1, 1)]; $gildedRose = new GildedRose($items); @@ -140,7 +140,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 0); } - public function test_aged_brie_than_sell_in_lower_then_zero() + public function test_aged_brie_then_sell_in_lower_then_zero() { $items = [new Item("Aged Brie", -1, 1)]; $gildedRose = new GildedRose($items); @@ -149,7 +149,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, -2); } - public function test_aged_brie_than_sell_id_is_zero() + public function test_aged_brie_then_sell_id_is_zero() { $items = [new Item("Aged Brie", 0, 1)]; $gildedRose = new GildedRose($items); @@ -158,7 +158,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, -1); } - public function test_aged_brie_than_quality_is_maximum() + public function test_aged_brie_then_quality_is_maximum() { $items = [new Item("Aged Brie", 1, 50)]; $gildedRose = new GildedRose($items); @@ -167,7 +167,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 0); } - public function test_aged_brie_than_quality_maximum_and_sell_in_lower_then_zero() + public function test_aged_brie_then_quality_maximum_and_sell_in_lower_then_zero() { $items = [new Item("Aged Brie", -1, 50)]; $gildedRose = new GildedRose($items); @@ -176,7 +176,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, -2); } - public function test_aged_brie_than_quality_maximum_and_sell_in_greater_then_zero() + public function test_aged_brie_then_quality_maximum_and_sell_in_greater_then_zero() { $items = [new Item("Aged Brie", 1, 50)]; $gildedRose = new GildedRose($items); @@ -185,7 +185,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 0); } - public function test_aged_brie_than_quality_one_of_maximum() + public function test_aged_brie_then_quality_one_of_maximum() { $items = [new Item("Aged Brie", 10, 49)]; $gildedRose = new GildedRose($items); @@ -194,4 +194,21 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase $this->assertEquals($items[0]->sell_in, 9); } + public function test_conjured_then_sell_in_greater_then_zero() + { + $items = [new Item("Conjured Mana Cake", 1, 5)]; + $gildedRose = new GildedRose($items); + $gildedRose->updateQuality(); + $this->assertEquals($items[0]->quality, 3); + $this->assertEquals($items[0]->sell_in, 0); + } + + public function test_conjured_then_sell_in_lower_then_zero() + { + $items = [new Item("Conjured Mana Cake", -1, 5)]; + $gildedRose = new GildedRose($items); + $gildedRose->updateQuality(); + $this->assertEquals($items[0]->quality, 1); + $this->assertEquals($items[0]->sell_in, -2); + } } \ No newline at end of file