mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 07:51:29 +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
|
public function updateQuality(): void
|
||||||
{
|
{
|
||||||
foreach ($this->items as $item) {
|
foreach ($this->items as $item) {
|
||||||
if ($item->name !== self::SULFURAS_HAND_OF_RAGNAROS) {
|
|
||||||
$item->decreaseSellDate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($item->name === self::AGED_BRIE) {
|
if ($item->name === self::AGED_BRIE) {
|
||||||
$item->increaseQuality();
|
(new AgedBrieCommand())->execute($item);
|
||||||
if ($item->isSellDatePassed()) {
|
|
||||||
$item->increaseQuality();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($item->name === self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT) {
|
if ($item->name === self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT) {
|
||||||
$item->increaseQuality();
|
(new BackstageCommand())->execute($item);
|
||||||
if ($item->sell_in <= 10) {
|
|
||||||
$item->increaseQuality();
|
|
||||||
}
|
|
||||||
if ($item->sell_in <= 5) {
|
|
||||||
$item->increaseQuality();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (in_array($item->name,
|
||||||
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();
|
self::AGED_BRIE,
|
||||||
if ($item->isSellDatePassed()) {
|
self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT,
|
||||||
$item->decreaseQuality();
|
self::SULFURAS_HAND_OF_RAGNAROS
|
||||||
}
|
]
|
||||||
}
|
) === false) {
|
||||||
|
(new NormalCommand())->execute($item);
|
||||||
if ($item->isSellDatePassed() && $item->name === self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT) {
|
|
||||||
$item->quality = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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