mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 16:01:42 +00:00
Refactor: remove duplicated conditional statement
- seperate handlePassesQuality
This commit is contained in:
parent
2bacc188d5
commit
87131ef926
@ -10,6 +10,11 @@ export class Item {
|
|||||||
this.sellIn = sellIn;
|
this.sellIn = sellIn;
|
||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleSellIn() {
|
||||||
|
// if (this.name === ITEMS.SURFRAS) return;
|
||||||
|
// this.sellIn--;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GildedRose {
|
export class GildedRose {
|
||||||
@ -19,6 +24,18 @@ export class GildedRose {
|
|||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlePassesQuality(item) {
|
||||||
|
if (item.name == ITEMS.PASSES) {
|
||||||
|
if (6 <= item.sellIn && item.sellIn < 11) {
|
||||||
|
item.quality += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.sellIn < 6) {
|
||||||
|
item.quality += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleIfSellInIs0(item) {
|
handleIfSellInIs0(item) {
|
||||||
if (item.sellIn >= 0) return;
|
if (item.sellIn >= 0) return;
|
||||||
|
|
||||||
@ -39,33 +56,21 @@ export class GildedRose {
|
|||||||
|
|
||||||
updateQuality() {
|
updateQuality() {
|
||||||
for (const item of this.items) {
|
for (const item of this.items) {
|
||||||
if (item.name != ITEMS.BRIE && item.name != ITEMS.PASSES) {
|
if (!item.quality) break;
|
||||||
if (!item.quality) break;
|
|
||||||
if (item.name != ITEMS.SURFRAS) {
|
|
||||||
item.quality -= 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (item.quality < 50) {
|
|
||||||
item.quality += 1;
|
|
||||||
|
|
||||||
if (item.name == ITEMS.PASSES) {
|
|
||||||
if (item.sellIn < 11) {
|
|
||||||
if (item.quality < 50) {
|
|
||||||
item.quality += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.sellIn < 6) {
|
|
||||||
if (item.quality >= 50) break;
|
|
||||||
item.quality += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (item.name != ITEMS.SURFRAS) {
|
if (item.name != ITEMS.SURFRAS) {
|
||||||
item.sellIn -= 1;
|
item.sellIn -= 1;
|
||||||
}
|
}
|
||||||
this.handleIfSellInIs0(item);
|
this.handleIfSellInIs0(item);
|
||||||
|
|
||||||
|
if (item.name != ITEMS.BRIE && item.name != ITEMS.PASSES) {
|
||||||
|
if (item.name === ITEMS.SURFRAS) break;
|
||||||
|
item.quality -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.quality >= 50) break;
|
||||||
|
item.quality += 1;
|
||||||
|
|
||||||
|
this.handlePassesQuality(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.items;
|
return this.items;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user