mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-14 22:21:20 +00:00
Finishes separating DailyUpdate processing according to type. Still in the same method.
This commit is contained in:
parent
c7eafcaeec
commit
0e52fc7c4b
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -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.<br>
|
||||
3. Extract Increasing/Decreasing Quality into a method.<br>
|
||||
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.<br>
|
||||
|
||||
|
||||
This is the state of the code now
|
||||
|
||||
Loading…
Reference in New Issue
Block a user