mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Add conjured items feature
This commit is contained in:
parent
abfd7796d7
commit
8250515a59
@ -9,6 +9,7 @@ final class GildedRose
|
|||||||
private const AGED_BRIE = 'Aged Brie';
|
private const AGED_BRIE = 'Aged Brie';
|
||||||
private const BACKSTAGE = 'Backstage passes to a TAFKAL80ETC concert';
|
private const BACKSTAGE = 'Backstage passes to a TAFKAL80ETC concert';
|
||||||
private const SHR = 'Sulfuras, Hand of Ragnaros';
|
private const SHR = 'Sulfuras, Hand of Ragnaros';
|
||||||
|
private const CONJURED = 'Conjured Mana Cake';
|
||||||
|
|
||||||
private const MAX_THRESHOLD = 50;
|
private const MAX_THRESHOLD = 50;
|
||||||
private const MIN_THRESHOLD = 0;
|
private const MIN_THRESHOLD = 0;
|
||||||
@ -33,6 +34,11 @@ final class GildedRose
|
|||||||
$item->quality = $this->subtractQuality($item);
|
$item->quality = $this->subtractQuality($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The quality of conjured items degrade twice as fast as normal items, so subtract once again
|
||||||
|
if ($this->isConjuredItem($item)) {
|
||||||
|
$item->quality = $this->subtractQuality($item);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->qualityIncreases($item)) {
|
if ($this->qualityIncreases($item)) {
|
||||||
$item->quality = $this->addQuality($item);
|
$item->quality = $this->addQuality($item);
|
||||||
|
|
||||||
@ -84,6 +90,11 @@ final class GildedRose
|
|||||||
return $item->sell_in < 0;
|
return $item->sell_in < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isConjuredItem(Item $item): bool
|
||||||
|
{
|
||||||
|
return $item->name === self::CONJURED;
|
||||||
|
}
|
||||||
|
|
||||||
private function subtractQuality(Item $item): int
|
private function subtractQuality(Item $item): int
|
||||||
{
|
{
|
||||||
$quality = $item->quality;
|
$quality = $item->quality;
|
||||||
|
|||||||
@ -16,6 +16,7 @@ class GildedRoseTest extends TestCase
|
|||||||
new Item('+5 Dexterity Vest', 10, 20),
|
new Item('+5 Dexterity Vest', 10, 20),
|
||||||
new Item('Aged Brie', 2, 0),
|
new Item('Aged Brie', 2, 0),
|
||||||
new Item('Sulfuras, Hand of Ragnaros', 0, 80),
|
new Item('Sulfuras, Hand of Ragnaros', 0, 80),
|
||||||
|
new Item('Conjured Mana Cake', 1, 6),
|
||||||
];
|
];
|
||||||
|
|
||||||
$gildedRose = new GildedRose($items);
|
$gildedRose = new GildedRose($items);
|
||||||
@ -30,5 +31,8 @@ class GildedRoseTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame(0, $items[2]->sell_in);
|
$this->assertSame(0, $items[2]->sell_in);
|
||||||
$this->assertSame(80, $items[2]->quality);
|
$this->assertSame(80, $items[2]->quality);
|
||||||
|
|
||||||
|
$this->assertSame(0, $items[3]->sell_in);
|
||||||
|
$this->assertSame(4, $items[3]->quality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user