mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-17 23:41:27 +00:00
Reduce nested statement and extract methods
This commit is contained in:
parent
468ff532ea
commit
9572804f09
@ -24,53 +24,54 @@ final class GildedRose
|
|||||||
public function updateQuality(): void
|
public function updateQuality(): void
|
||||||
{
|
{
|
||||||
foreach ($this->items as $item) {
|
foreach ($this->items as $item) {
|
||||||
|
if ($item->name === 'Sulfuras, Hand of Ragnaros') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($item->name === 'Aged Brie' || $item->name === 'Backstage passes to a TAFKAL80ETC concert') {
|
if ($item->name === 'Aged Brie' || $item->name === 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
if ($item->quality < 50) {
|
if ($item->quality < 50) {
|
||||||
$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) {
|
||||||
if ($item->quality < 50) {
|
$this->increaseQuality($item);
|
||||||
$item->quality = $item->quality + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($item->sellIn < 6) {
|
if ($item->sellIn < 6) {
|
||||||
if ($item->quality < 50) {
|
$this->increaseQuality($item);
|
||||||
$item->quality = $item->quality + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($item->quality > 0) {
|
$this->decreaseQuality($item);
|
||||||
if ($item->name !== 'Sulfuras, Hand of Ragnaros') {
|
|
||||||
$item->quality = $item->quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($item->name === 'Sulfuras, Hand of Ragnaros') {
|
$item->sellIn = $item->sellIn - 1;
|
||||||
} else {
|
|
||||||
$item->sellIn = $item->sellIn - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($item->sellIn < 0) {
|
if ($item->sellIn < 0) {
|
||||||
if ($item->name === 'Aged Brie') {
|
if ($item->name === 'Aged Brie') {
|
||||||
if ($item->quality < 50) {
|
$this->increaseQuality($item);
|
||||||
$item->quality = $item->quality + 1;
|
|
||||||
}
|
|
||||||
} 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 {
|
||||||
if ($item->quality > 0) {
|
$this->decreaseQuality($item);
|
||||||
if ($item->name === 'Sulfuras, Hand of Ragnaros') {
|
|
||||||
} else {
|
|
||||||
$item->quality = $item->quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user