diff --git a/php/src/GildedRose.php b/php/src/GildedRose.php index cfb7f78a..33a29b76 100644 --- a/php/src/GildedRose.php +++ b/php/src/GildedRose.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace GildedRose; -final class GildedRose +use GildedRose\GildedRoseInterface; + +final class GildedRose implements GildedRoseInterface { /** * @var Item[] @@ -19,51 +21,70 @@ final class GildedRose public function updateQuality(): void { 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; - } - } - } + + $this->firstProcessingRule($item); + + $this->secondProcessingRule($item); + + $this->thirdProcessingRule($item); + } + } + + public function firstProcessingRule(&$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; } } - - 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') { - $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; } - } else { - $item->quality = $item->quality - $item->quality; } - } else { - if ($item->quality < 50) { - $item->quality = $item->quality + 1; + if ($item->sell_in < 6) { + if ($item->quality < 50) { + $item->quality = $item->quality + 1; + } } } } } } + + 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; + } + } + } + } + } diff --git a/php/src/GildedRoseInterface.php b/php/src/GildedRoseInterface.php new file mode 100644 index 00000000..65e82f3a --- /dev/null +++ b/php/src/GildedRoseInterface.php @@ -0,0 +1,18 @@ +