mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-14 22:21:20 +00:00
refactor: improved readability and extract mutations
This commit is contained in:
parent
6564125ba3
commit
58205b5740
@ -9,54 +9,61 @@ class GildedRose {
|
|||||||
|
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
if (!item.getName().equals("Aged Brie")
|
boolean isAgedBrie = item.getName().equals("Aged Brie");
|
||||||
&& !item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
boolean isSulfuras = item.getName().equals("Sulfuras, Hand of Ragnaros");
|
||||||
if (item.quality > 0) {
|
boolean passesToTafkalConcert = item.getName().equals("Backstage passes to a TAFKAL80ETC concert");
|
||||||
if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
|
|
||||||
item.quality = item.quality - 1;
|
if (!isAgedBrie && !passesToTafkalConcert) {
|
||||||
}
|
if (item.quality > 0 && !isSulfuras) {
|
||||||
|
deductOneFromQuality(item);
|
||||||
}
|
}
|
||||||
} else {
|
} else if(item.quality < 50) {
|
||||||
if (item.quality < 50) {
|
addOneToQuality(item);
|
||||||
item.quality = item.quality + 1;
|
|
||||||
|
|
||||||
if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (passesToTafkalConcert) {
|
||||||
if (item.sellIn < 11) {
|
if (item.sellIn < 11 && item.quality < 50) {
|
||||||
if (item.quality < 50) {
|
addOneToQuality(item);
|
||||||
item.quality = item.quality + 1;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.sellIn < 6) {
|
if (item.sellIn < 6 && item.quality < 50) {
|
||||||
if (item.quality < 50) {
|
addOneToQuality(item);
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
|
if (!isSulfuras) {
|
||||||
item.sellIn = item.sellIn - 1;
|
deductSellIn(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.sellIn < 0) {
|
if (item.sellIn < 0) {
|
||||||
if (!item.getName().equals("Aged Brie")) {
|
if (!isAgedBrie) {
|
||||||
if (!item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (!passesToTafkalConcert) {
|
||||||
if (item.quality > 0) {
|
if (item.quality > 0 && !isSulfuras) {
|
||||||
if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
|
deductOneFromQuality(item);
|
||||||
item.quality = item.quality - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
item.quality = 0;
|
setQualityToZero(item);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (item.quality < 50) {
|
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
}
|
||||||
|
} else if ((item.quality < 50)) {
|
||||||
|
addOneToQuality(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setQualityToZero(Item item) {
|
||||||
|
item.quality = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deductSellIn(Item item) {
|
||||||
|
item.sellIn--;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOneToQuality(Item item) {
|
||||||
|
item.quality++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deductOneFromQuality(Item item) {
|
||||||
|
item.quality--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user