Refactored GildedRose

This commit is contained in:
Elliott Allmann 2023-02-24 16:39:43 -08:00
parent 1255acfa93
commit eecaf8fbc0

View File

@ -22,51 +22,45 @@ final class GildedRose
public function updateQuality(): void
{
foreach ($this->items as $item) {
if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') {
if ($item->quality > 0) {
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
$item->quality = $item->quality - 1;
}
}
} else {
if ($item->quality < 50) {
$item->quality = $item->quality + 1;
if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') {
if ($item->sellIn < 11) {
if ($item->quality < 50) {
$item->quality = $item->quality + 1;
}
}
if ($item->sellIn < 6) {
if ($item->quality < 50) {
$item->quality = $item->quality + 1;
}
}
}
}
}
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
$item->sellIn = $item->sellIn - 1;
}
if ($item->sellIn < 0) {
if ($item->name != 'Aged Brie') {
if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') {
if ($item->quality > 0) {
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
$item->quality = $item->quality - 1;
}
}
} else {
$item->quality = $item->quality - $item->quality;
}
} else {
switch ($item->name) {
case 'Aged Brie':
$item->sellIn--;
if ($item->quality < 50) {
$item->quality = $item->quality + 1;
$item->quality++;
}
}
}
break;
case 'Backstage passes to a TAFKAL80ETC concert':
if (($item->quality < 50) && ($item->sellIn >= 0)) {
$item->quality++;
if (($item->sellIn < 11) && ($item->quality < 50)) {
$item->quality++;
}
if (($item->sellIn < 6) && ($item->quality < 50)) {
$item->quality++;
}
}
$item->sellIn--;
// If we are past the concert date, set the quality to 0.
if ($item->sellIn < 0) {
$item->quality = 0;
}
break;
case 'Sulfuras, Hand of Ragnaros':
$item->quality = 80;
break;
default: // Normal Items
$item->sellIn--;
if ($item->quality > 0) {
$item->quality--;
if (($item->sellIn < 0) && ($item->quality > 0)) {
$item->quality--;
}
}
break;
} // END switch
}
}
}