diff --git a/csharpcore/GildedRose/GildedRose.cs b/csharpcore/GildedRose/GildedRose.cs
index 528cbe67..c10dac65 100644
--- a/csharpcore/GildedRose/GildedRose.cs
+++ b/csharpcore/GildedRose/GildedRose.cs
@@ -31,7 +31,8 @@ public class GildedRose
!IsBackstagePassesItem(item) &&
!IsBetterWithAgeItem(item));
-
+ private static bool IsExpired(Item item) => item.SellIn < 0;
+
private static void IncreaseQuality(Item item, int byValue)
{
item.Quality = int.Min(item.Quality + byValue, MaxQuality);
@@ -47,50 +48,45 @@ public class GildedRose
{
if (IsLegendaryItem(item)) return;
+ item.SellIn -= 1;
+
if (IsRegularItem(item))
{
DecreaseQuality(item, 1);
+ if (IsExpired(item))
+ {
+ DecreaseQuality(item, 1);
+ }
}
if (IsBetterWithAgeItem(item))
{
IncreaseQuality(item, 1);
+ if (IsExpired(item))
+ {
+ IncreaseQuality(item, 1);
+ }
}
if(IsBackstagePassesItem(item))
{
- if (item.SellIn > 10)
+ if (item.SellIn > 9)
{
IncreaseQuality(item, 1);
}
- else if (item.SellIn > 5)
+ else if (item.SellIn > 4)
{
IncreaseQuality(item, 2);
}
- else
+ else if (!IsExpired(item))
{
IncreaseQuality(item, 3);
}
- }
-
- item.SellIn = item.SellIn - 1;
-
- if (item.SellIn < 0)
- {
- if (IsRegularItem(item))
- {
- DecreaseQuality(item, 1);
- }
-
- if(IsBackstagePassesItem(item))
+ else //Expired
{
DecreaseQuality(item, item.Quality);
}
-
- if(IsBetterWithAgeItem(item))
- {
- IncreaseQuality(item, 1);
- }
}
+
}
}
\ No newline at end of file
diff --git a/csharpcore/GildedRose/RefactoringDiary.md b/csharpcore/GildedRose/RefactoringDiary.md
index a19b7d4f..5d602418 100644
--- a/csharpcore/GildedRose/RefactoringDiary.md
+++ b/csharpcore/GildedRose/RefactoringDiary.md
@@ -13,7 +13,7 @@ I decorated these tests with `[Ignore]` until I get to a stage in the refactorin
2. small refactorings of the UpdateQuality() method to make it more readable and separate the different (unrelated) handling of the different types.
3. Extract Increasing/Decreasing Quality into a method.
It feels like Quality should have been a TinyType that manages its own limits. However, since we're not allowed to change Item, I'm just extracting a method.
-
+4. Separated the processing of the different types from each other.
This is the state of the code now