From a3cdf07cec61c70a38bcba85e5927b3e5e001c12 Mon Sep 17 00:00:00 2001 From: MatheusMW21 Date: Tue, 2 Sep 2025 20:47:26 -0300 Subject: [PATCH] refactor: refactoring updateQuality logic --- csharp.NUnit/GildedRose/GildedRose.cs | 99 ++++++++++----------------- 1 file changed, 36 insertions(+), 63 deletions(-) diff --git a/csharp.NUnit/GildedRose/GildedRose.cs b/csharp.NUnit/GildedRose/GildedRose.cs index c08bf5f8..dd3ea1ce 100644 --- a/csharp.NUnit/GildedRose/GildedRose.cs +++ b/csharp.NUnit/GildedRose/GildedRose.cs @@ -13,77 +13,50 @@ public class GildedRose public void UpdateQuality() { - for (var i = 0; i < Items.Count; i++) + foreach (var item in Items) { - if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + if (item.Name == "Sulfuras, Hand of Ragnaros") + continue; + + item.SellIn--; + + switch (item.Name) { - if (Items[i].Quality > 0) - { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") + case "Aged Brie": + IncreaseQuality(item); + if (item.SellIn < 0) + IncreaseQuality(item); + break; + + case "Backstage passes to a TAFKAL80ETC concert": + if (item.SellIn < 0) { - Items[i].Quality = Items[i].Quality - 1; - } - } - } - else - { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - - if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert") - { - if (Items[i].SellIn < 11) - { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } - } - - if (Items[i].SellIn < 6) - { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } - } - } - } - } - - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") - { - Items[i].SellIn = Items[i].SellIn - 1; - } - - if (Items[i].SellIn < 0) - { - if (Items[i].Name != "Aged Brie") - { - if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") - { - if (Items[i].Quality > 0) - { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") - { - Items[i].Quality = Items[i].Quality - 1; - } - } + item.Quality = 0; } else { - Items[i].Quality = Items[i].Quality - Items[i].Quality; + IncreaseQuality(item); + if (item.SellIn < 10) IncreaseQuality(item); + if (item.SellIn < 5) IncreaseQuality(item); } - } - else - { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } - } + break; + + default: + DecreaseQuality(item); + if (item.SellIn < 0) + DecreaseQuality(item); + break; } } } + + private void IncreaseQuality(Item item) + { + if (item.Quality < 50) item.Quality++; + } + + private void DecreaseQuality(Item item) + { + if (item.Quality > 0) item.Quality--; + } } \ No newline at end of file