mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-17 23:41:27 +00:00
Delegate functions to item itself
This commit is contained in:
parent
9572804f09
commit
af972b4009
@ -33,45 +33,30 @@ final class GildedRose
|
|||||||
$item->quality = $item->quality + 1;
|
$item->quality = $item->quality + 1;
|
||||||
if ($item->name === 'Backstage passes to a TAFKAL80ETC concert') {
|
if ($item->name === 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
if ($item->sellIn < 11) {
|
if ($item->sellIn < 11) {
|
||||||
$this->increaseQuality($item);
|
$item->increaseQuality();
|
||||||
}
|
}
|
||||||
if ($item->sellIn < 6) {
|
if ($item->sellIn < 6) {
|
||||||
$this->increaseQuality($item);
|
$item->increaseQuality();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->decreaseQuality($item);
|
$item->decreaseQuality();
|
||||||
}
|
}
|
||||||
|
|
||||||
$item->sellIn = $item->sellIn - 1;
|
$item->sellIn = $item->sellIn - 1;
|
||||||
|
|
||||||
if ($item->sellIn < 0) {
|
if ($item->sellIn < 0) {
|
||||||
if ($item->name === 'Aged Brie') {
|
if ($item->name === 'Aged Brie') {
|
||||||
$this->increaseQuality($item);
|
$item->increaseQuality();
|
||||||
} else {
|
} else {
|
||||||
if ($item->name === 'Backstage passes to a TAFKAL80ETC concert') {
|
if ($item->name === 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
$item->quality = $item->quality - $item->quality;
|
$item->quality = $item->quality - $item->quality;
|
||||||
} else {
|
} else {
|
||||||
$this->decreaseQuality($item);
|
$item->decreaseQuality();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function increaseQuality(Item &$item): void
|
|
||||||
{
|
|
||||||
if ($item->quality >= 50) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$item->quality += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function decreaseQuality(Item &$item): void
|
|
||||||
{
|
|
||||||
if ($item->quality > 0) {
|
|
||||||
$item->quality -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,4 +23,20 @@ final class Item
|
|||||||
{
|
{
|
||||||
return "{$this->name}, {$this->sellIn}, {$this->quality}";
|
return "{$this->name}, {$this->sellIn}, {$this->quality}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function increaseQuality(): void
|
||||||
|
{
|
||||||
|
if ($this->quality >= 50) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->quality += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function decreaseQuality(): void
|
||||||
|
{
|
||||||
|
if ($this->quality <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->quality -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user