mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Move body from client to command classes
This commit is contained in:
parent
795c150ab5
commit
b6b41e3d94
@ -22,38 +22,70 @@ final class GildedRose
|
||||
public function updateQuality(): void
|
||||
{
|
||||
foreach ($this->items as $item) {
|
||||
if ($item->name !== self::SULFURAS_HAND_OF_RAGNAROS) {
|
||||
$item->decreaseSellDate();
|
||||
}
|
||||
|
||||
if ($item->name === self::AGED_BRIE) {
|
||||
$item->increaseQuality();
|
||||
if ($item->isSellDatePassed()) {
|
||||
$item->increaseQuality();
|
||||
}
|
||||
(new AgedBrieCommand())->execute($item);
|
||||
}
|
||||
|
||||
if ($item->name === self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT) {
|
||||
$item->increaseQuality();
|
||||
if ($item->sell_in <= 10) {
|
||||
$item->increaseQuality();
|
||||
}
|
||||
if ($item->sell_in <= 5) {
|
||||
$item->increaseQuality();
|
||||
}
|
||||
(new BackstageCommand())->execute($item);
|
||||
}
|
||||
|
||||
|
||||
if (in_array($item->name, [self::AGED_BRIE, self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT, self::SULFURAS_HAND_OF_RAGNAROS]) === false) {
|
||||
$item->decreaseQuality();
|
||||
if ($item->isSellDatePassed()) {
|
||||
$item->decreaseQuality();
|
||||
}
|
||||
}
|
||||
|
||||
if ($item->isSellDatePassed() && $item->name === self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT) {
|
||||
$item->quality = 0;
|
||||
if (in_array($item->name,
|
||||
[
|
||||
self::AGED_BRIE,
|
||||
self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT,
|
||||
self::SULFURAS_HAND_OF_RAGNAROS
|
||||
]
|
||||
) === false) {
|
||||
(new NormalCommand())->execute($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class AgedBrieCommand
|
||||
{
|
||||
public function execute(Item $item): void
|
||||
{
|
||||
$item->decreaseSellDate();
|
||||
|
||||
$item->increaseQuality();
|
||||
if ($item->isSellDatePassed()) {
|
||||
$item->increaseQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class BackstageCommand
|
||||
{
|
||||
public function execute(Item $item): void
|
||||
{
|
||||
$item->decreaseSellDate();
|
||||
|
||||
if ($item->isSellDatePassed()) {
|
||||
$item->quality = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
$item->increaseQuality();
|
||||
if ($item->sell_in <= 10) {
|
||||
$item->increaseQuality();
|
||||
}
|
||||
|
||||
if ($item->sell_in <= 5) {
|
||||
$item->increaseQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class NormalCommand
|
||||
{
|
||||
public function execute(Item $item): void
|
||||
{
|
||||
$item->decreaseSellDate();
|
||||
$item->decreaseQuality();
|
||||
if ($item->isSellDatePassed()) {
|
||||
$item->decreaseQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user