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

This commit is contained in:
Sam Burns 2024-01-24 15:59:15 +00:00
parent ea9b680b55
commit df68a125cb
3 changed files with 14 additions and 3 deletions

View File

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

View File

@ -16,9 +16,15 @@ class BrieItem implements GildedRoseItem
public function ageByOneDay(): void
{
$this->item->sellIn -= 1;
$this->item->quality = min(50, $this->getNewQuality($this->item->quality, $this->item->sellIn));
}
if ($this->item->quality < 50) {
$this->item->quality += 1;
private function getNewQuality(int $previousQuality, int $sellIn): int
{
if ($sellIn < 0) {
return $previousQuality + 2;
}
return $previousQuality + 1;
}
}

View File

@ -14,3 +14,8 @@ Feature: Brie quality changes
Given some brie with a sell-in of 20 and a quality of 50
When I update the quality
Then the item should have a quality of 50
Scenario: Aged brie gets better faster after sell-by date
Given some brie with a sell-in of 0 and a quality of 20
When I update the quality
Then the item should have a quality of 22