diff --git a/php7/fixtures/texttest_fixture.php b/php7/fixtures/texttest_fixture.php index a5676658..1bbd49b4 100644 --- a/php7/fixtures/texttest_fixture.php +++ b/php7/fixtures/texttest_fixture.php @@ -3,6 +3,7 @@ require_once __DIR__ . '/../vendor/autoload.php'; use App\GildedRose; +use App\GildedRoseProductsService; use App\Item; echo "OMGHAI!\n"; @@ -17,10 +18,12 @@ $items = array( new Item('Backstage passes to a TAFKAL80ETC concert', 10, 49), new Item('Backstage passes to a TAFKAL80ETC concert', 5, 49), // this conjured item does not work properly yet - new Item('Conjured Mana Cake', 3, 6) + new Item('Conjured Mana Cake', 3, 6), + new Item('Conjured Mana Cake', 3, -1) ); -$app = new GildedRose($items); +$gildedRose = new GildedRose($items); +$app = new GildedRoseProductsService($gildedRose); $days = 2; if (count($argv) > 1) { diff --git a/php7/src/GildedRose.php b/php7/src/GildedRose.php index 5a7cd7c9..fe36fb25 100644 --- a/php7/src/GildedRose.php +++ b/php7/src/GildedRose.php @@ -2,49 +2,36 @@ namespace App; -final class GildedRose { +final class GildedRose implements GildedRoseInterface { + + const AGED_BRIE = 'Aged Brie'; + const BACKSTAGE_PASS = 'Backstage passes to a TAFKAL80ETC concert'; + const SULFULRAS_RAGNAROS = 'Sulfuras, Hand of Ragnaros'; + const CONJURED = 'Conjured Mana Cake'; + const SELL_IN_ZERO = 0; + const QUALITY_ZERO = 0; + const QUALITY_MID = 11; + const QUALITY_LOW = 6; + const QUALITY_MAX = 50; private $items = []; + public function __construct($items) { $this->items = $items; } - public function updateQuality() { - foreach ($this->items as $item) { - if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') { - if ($item->quality > 0) { - if ($item->name != 'Sulfuras, Hand of Ragnaros') { - $item->quality = $item->quality - 1; - } - } - } else { - if ($item->quality < 50) { - $item->quality = $item->quality + 1; - if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') { - if ($item->sell_in < 11) { - if ($item->quality < 50) { - $item->quality = $item->quality + 1; - } - } - if ($item->sell_in < 6) { - if ($item->quality < 50) { - $item->quality = $item->quality + 1; - } - } - } - } - } - - if ($item->name != 'Sulfuras, Hand of Ragnaros') { - $item->sell_in = $item->sell_in - 1; - } - - if ($item->sell_in < 0) { - if ($item->name != 'Aged Brie') { - if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') { - if ($item->quality > 0) { - if ($item->name != 'Sulfuras, Hand of Ragnaros') { + public function getItems(){ + return $this->items; + } + + public function checkQualityExceptSulfurasWhereSellInZero(Item $item) + { + if ($item->sell_in < self::SELL_IN_ZERO) { + if ($item->name != self::AGED_BRIE) { + if ($item->name != self::BACKSTAGE_PASS) { + if ($item->quality > self::QUALITY_ZERO) { + if ($item->name != self::SULFULRAS_RAGNAROS) { $item->quality = $item->quality - 1; } } @@ -52,12 +39,51 @@ final class GildedRose { $item->quality = $item->quality - $item->quality; } } else { - if ($item->quality < 50) { + if ($item->quality < self::QUALITY_MAX) { + $item->quality = $item->quality + 1; + } + } + } + + } + + public function checkQualityExeceptSulfurasForBrieAndPassProducts(Item $item) { + if (!($item->name != GildedRose::AGED_BRIE and $item->name != GildedRose::BACKSTAGE_PASS)) { + if ($item->quality < self::QUALITY_MAX) { + $item->quality = $item->quality + 1; + if ($item->name == self::BACKSTAGE_PASS) { + if ($item->sell_in < self::QUALITY_MID) { + $item->quality = $item->quality + 1; + } + if ($item->sell_in < self::QUALITY_LOW) { $item->quality = $item->quality + 1; } } } } + } + + public function checkQualityLessThanZeroExceptSulfuras(Item $item){ + if ($item->name != GildedRose::AGED_BRIE and $item->name != GildedRose::BACKSTAGE_PASS) { + if ($item->quality > self::QUALITY_ZERO) { + if ($item->name != self::SULFULRAS_RAGNAROS) { + if($item->name == self::CONJURED) { + $item->quality = ($item->quality == 1) ? $item->quality - 1 : $item->quality - 2; + }else { + $item->quality = $item->quality - 1; + } + } + } + } + } + + public function reduceSellInExceptSulfuras(Item $item){ + //reduce sellin + if ($item->name != self::SULFULRAS_RAGNAROS) { + $item->sell_in = $item->sell_in - 1; + } + } + } diff --git a/php7/src/GildedRoseInterface.php b/php7/src/GildedRoseInterface.php new file mode 100644 index 00000000..6d4628cd --- /dev/null +++ b/php7/src/GildedRoseInterface.php @@ -0,0 +1,16 @@ +GildedRose = $gildedRose; + } + + public function updateQuality() { + + foreach ($this->GildedRose->getItems() as $item) { + $this->GildedRose->checkQualityLessThanZeroExceptSulfuras($item); + $this->GildedRose->checkQualityExeceptSulfurasForBrieAndPassProducts($item); + $this->GildedRose->reduceSellInExceptSulfuras($item); + $this->GildedRose->checkQualityExceptSulfurasWhereSellInZero($item); + } + } +} \ No newline at end of file