diff --git a/php/src/FirstProcessingRule.php b/php/src/FirstProcessingRule.php new file mode 100644 index 00000000..a275d121 --- /dev/null +++ b/php/src/FirstProcessingRule.php @@ -0,0 +1,46 @@ +item = $item; + } + + public function firstProcessingRule() + { + $item = $this->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; + } + } + } + } + } + } + +} \ No newline at end of file diff --git a/php/src/GildedRose.php b/php/src/GildedRose.php index 33a29b76..c6bf73de 100644 --- a/php/src/GildedRose.php +++ b/php/src/GildedRose.php @@ -4,9 +4,8 @@ declare(strict_types=1); namespace GildedRose; -use GildedRose\GildedRoseInterface; -final class GildedRose implements GildedRoseInterface +final class GildedRose { /** * @var Item[] @@ -22,68 +21,17 @@ final class GildedRose implements GildedRoseInterface { foreach ($this->items as $item) { - $this->firstProcessingRule($item); + $firstItem = new FirstProcessingRule($item); - $this->secondProcessingRule($item); + $firstItem->firstProcessingRule(); - $this->thirdProcessingRule($item); - } - } + $secondItem = new SecondProcessingRule($item); - public function firstProcessingRule(&$item) - { + $secondItem->secondProcessingRule(); - 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; - } - } - } - } - } - } + $thirdItem = new ThirdProcessingRule($item); - public function secondProcessingRule(&$item) - { - if ($item->name != 'Sulfuras, Hand of Ragnaros') { - $item->sell_in = $item->sell_in - 1; - } - - } - - public function thirdProcessingRule(&$item) - { - 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') { - $item->quality = $item->quality - 1; - } - } - } else { - $item->quality = $item->quality - $item->quality; - } - } else { - if ($item->quality < 50) { - $item->quality = $item->quality + 1; - } - } + $thirdItem->thirdProcessingRule(); } } diff --git a/php/src/GildedRoseInterface.php b/php/src/GildedRoseInterface.php deleted file mode 100644 index 65e82f3a..00000000 --- a/php/src/GildedRoseInterface.php +++ /dev/null @@ -1,18 +0,0 @@ -item = $item; + } + + public function secondProcessingRule() + { + $item = $this->item; + + if ($item->name != 'Sulfuras, Hand of Ragnaros') { + $item->sell_in = $item->sell_in - 1; + } + + } + +} \ No newline at end of file diff --git a/php/src/ThirdProcessingRule.php b/php/src/ThirdProcessingRule.php new file mode 100644 index 00000000..634ecbc0 --- /dev/null +++ b/php/src/ThirdProcessingRule.php @@ -0,0 +1,37 @@ +item = $item; + } + + public function thirdProcessingRule() + { + $item = $this->item; + + 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') { + $item->quality = $item->quality - 1; + } + } + } else { + $item->quality = $item->quality - $item->quality; + } + } else { + if ($item->quality < 50) { + $item->quality = $item->quality + 1; + } + } + } + } + +} \ No newline at end of file