Use consts and change way of assigning properties

This commit is contained in:
Kacper Majczak 2022-09-12 13:05:01 +02:00
parent 44085d93d0
commit e0ab06959b

View File

@ -6,6 +6,9 @@ namespace GildedRose;
final class GildedRose
{
private const SULFURAS_HAND_OF_RAGNAROS = 'Sulfuras, Hand of Ragnaros';
private const BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT = 'Backstage passes to a TAFKAL80ETC concert';
private const AGED_BRIE = 'Aged Brie';
/**
* @var Item[]
*/
@ -19,51 +22,56 @@ 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->name != self::AGED_BRIE && $item->name != self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT) {
if ($item->quality > 0) {
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
$item->quality = $item->quality - 1;
if ($item->name != self::SULFURAS_HAND_OF_RAGNAROS) {
$item->quality -= 1;
}
}
} else {
if ($item->quality < 50) {
$item->quality = $item->quality + 1;
if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') {
$item->quality += 1;
if ($item->name == self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT) {
if ($item->sell_in < 11) {
if ($item->quality < 50) {
$item->quality = $item->quality + 1;
$item->quality += 1;
}
}
if ($item->sell_in < 6) {
if ($item->quality < 50) {
$item->quality = $item->quality + 1;
$item->quality += 1;
}
}
}
}
}
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
$item->sell_in = $item->sell_in - 1;
if ($item->name != self::SULFURAS_HAND_OF_RAGNAROS) {
$item->sell_in -= 1;
}
if ($item->sell_in < 0) {
if ($item->name != 'Aged Brie') {
if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') {
if ($this->isSellDatePassed($item)) {
if ($item->name != self::AGED_BRIE) {
if ($item->name != self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT) {
if ($item->quality > 0) {
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
$item->quality = $item->quality - 1;
if ($item->name != self::SULFURAS_HAND_OF_RAGNAROS) {
$item->quality -= 1;
}
}
} else {
$item->quality = $item->quality - $item->quality;
$item->quality = 0;
}
} else {
if ($item->quality < 50) {
$item->quality = $item->quality + 1;
$item->quality += 1;
}
}
}
}
}
private function isSellDatePassed($item): bool
{
return $item->sell_in < 0;
}
}