To begin taking advantage of new domain, use wrt backstage passes, and fix business logics

This commit is contained in:
Sam Burns 2024-01-24 15:52:46 +00:00
parent df7caf6747
commit 4562b6d688
2 changed files with 15 additions and 13 deletions

View File

@ -26,7 +26,7 @@ final class GildedRose
{ {
foreach ($this->items as $item) { foreach ($this->items as $item) {
if ($item->name === 'Sulfuras, Hand of Ragnaros') { if ($item->name === 'Sulfuras, Hand of Ragnaros' || $item->name === 'Backstage passes to a TAFKAL80ETC concert') {
$gildedRoseItem = $this->gildedRoseItemFactory->createGildedRoseItem($item); $gildedRoseItem = $this->gildedRoseItemFactory->createGildedRoseItem($item);
$gildedRoseItem->ageByOneDay(); $gildedRoseItem->ageByOneDay();
continue; continue;

View File

@ -16,21 +16,23 @@ class BackstagePassItem implements GildedRoseItem
public function ageByOneDay(): void public function ageByOneDay(): void
{ {
$this->item->sellIn -= 1; $this->item->sellIn -= 1;
$this->item->quality = min(50, $this->getNewQuality($this->item->quality, $this->item->sellIn));
}
if ($this->item->quality < 50) { private function getNewQuality(int $previousQuality, int $sellIn): int
$this->item->quality += 1; {
if ($sellIn < 0) {
if ($this->item->sellIn <= 10 && $this->item->quality < 50) { return 0;
$this->item->quality += 1;
}
if ($this->item->sellIn <= 5 && $this->item->quality < 50) {
$this->item->quality += 1;
}
} }
if ($this->item->sellIn < 0) { if ($sellIn < 5) {
$this->item->quality = 0; return $previousQuality + 3;
} }
if ($sellIn < 10) {
return $previousQuality + 2;
}
return $previousQuality + 1;
} }
} }