mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-14 22:21:20 +00:00
To begin taking advantage of new domain, use wrt brie, and fix business logics
This commit is contained in:
parent
ea9b680b55
commit
df68a125cb
@ -26,7 +26,7 @@ final class GildedRose
|
|||||||
{
|
{
|
||||||
foreach ($this->items as $item) {
|
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 = $this->gildedRoseItemFactory->createGildedRoseItem($item);
|
||||||
$gildedRoseItem->ageByOneDay();
|
$gildedRoseItem->ageByOneDay();
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@ -16,9 +16,15 @@ class BrieItem 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) {
|
||||||
|
return $previousQuality + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $previousQuality + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,3 +14,8 @@ Feature: Brie quality changes
|
|||||||
Given some brie with a sell-in of 20 and a quality of 50
|
Given some brie with a sell-in of 20 and a quality of 50
|
||||||
When I update the quality
|
When I update the quality
|
||||||
Then the item should have a quality of 50
|
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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user