From 4684969140349ca62aa91a48463b22dc7bb6161b Mon Sep 17 00:00:00 2001 From: Sarah Ashri Date: Tue, 12 Mar 2024 13:40:35 +1000 Subject: [PATCH] Refactoring - extract UpdateQuality(Item) to method --- csharp/GildedRose.cs | 86 ++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/csharp/GildedRose.cs b/csharp/GildedRose.cs index c60d97a0..a87e41d6 100644 --- a/csharp/GildedRose.cs +++ b/csharp/GildedRose.cs @@ -12,75 +12,77 @@ namespace csharp public void UpdateQuality() { - for (var i = 0; i < Items.Count; i++) + Items.ForEach(item => UpdateQuality(item)); + } + + private void UpdateQuality(Item item) + { + if (item.Name != "Aged Brie" && item.Name != "Backstage passes to a TAFKAL80ETC concert") { - if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + if (item.Quality > 0) { - if (Items[i].Quality > 0) + if (item.Name != "Sulfuras, Hand of Ragnaros") { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") - { - Items[i].Quality = Items[i].Quality - 1; - } + item.Quality = item.Quality - 1; } } - else + } + else + { + if (item.Quality < 50) { - if (Items[i].Quality < 50) + item.Quality = item.Quality + 1; + + if (item.Name == "Backstage passes to a TAFKAL80ETC concert") { - Items[i].Quality = Items[i].Quality + 1; - - if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert") + if (item.SellIn < 11) { - if (Items[i].SellIn < 11) + if (item.Quality < 50) { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } + item.Quality = item.Quality + 1; } + } - if (Items[i].SellIn < 6) + if (item.SellIn < 6) + { + if (item.Quality < 50) { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } + item.Quality = item.Quality + 1; } } } } + } - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") - { - Items[i].SellIn = Items[i].SellIn - 1; - } + if (item.Name != "Sulfuras, Hand of Ragnaros") + { + item.SellIn = item.SellIn - 1; + } - if (Items[i].SellIn < 0) + if (item.SellIn < 0) + { + if (item.Name != "Aged Brie") { - if (Items[i].Name != "Aged Brie") + if (item.Name != "Backstage passes to a TAFKAL80ETC concert") { - if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + if (item.Quality > 0) { - if (Items[i].Quality > 0) + if (item.Name != "Sulfuras, Hand of Ragnaros") { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") - { - Items[i].Quality = Items[i].Quality - 1; - } + item.Quality = item.Quality - 1; } } - else - { - Items[i].Quality = Items[i].Quality - Items[i].Quality; - } } else { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } + item.Quality = item.Quality - item.Quality; + } + } + else + { + if (item.Quality < 50) + { + item.Quality = item.Quality + 1; } } }