mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-20 17:01:06 +00:00
To begin taking advantage of new domain, use wrt backstage passes, and fix business logics
This commit is contained in:
parent
df7caf6747
commit
4562b6d688
@ -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;
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user