mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Move classes to separate files
This commit is contained in:
parent
d18f1c7e6f
commit
e2a1459192
18
php/src/AgedBrieCommand.php
Normal file
18
php/src/AgedBrieCommand.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GildedRose;
|
||||
|
||||
final class AgedBrieCommand implements Command
|
||||
{
|
||||
public function execute(Item $item): void
|
||||
{
|
||||
$item->decreaseSellDate();
|
||||
|
||||
$item->increaseQuality();
|
||||
if ($item->isSellDatePassed()) {
|
||||
$item->increaseQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
27
php/src/BackstageCommand.php
Normal file
27
php/src/BackstageCommand.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GildedRose;
|
||||
|
||||
final class BackstageCommand implements Command
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
10
php/src/Command.php
Normal file
10
php/src/Command.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GildedRose;
|
||||
|
||||
interface Command
|
||||
{
|
||||
public function execute(Item $item): void;
|
||||
}
|
||||
35
php/src/CommandFactory.php
Normal file
35
php/src/CommandFactory.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GildedRose;
|
||||
|
||||
final class CommandFactory
|
||||
{
|
||||
private const SULFURAS_HAND_OF_RAGNAROS = 'Sulfuras, Hand of Ragnaros';
|
||||
private const BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT = 'Backstage passes to a TAFKAL80ETC concert';
|
||||
private const AGED_BRIE = 'Aged Brie';
|
||||
|
||||
public function createFor(string $itemName): Command
|
||||
{
|
||||
if ($itemName === self::AGED_BRIE) {
|
||||
return new AgedBrieCommand();
|
||||
}
|
||||
|
||||
if ($itemName === self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT) {
|
||||
return new BackstageCommand();
|
||||
}
|
||||
|
||||
if (in_array($itemName,
|
||||
[
|
||||
self::AGED_BRIE,
|
||||
self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT,
|
||||
self::SULFURAS_HAND_OF_RAGNAROS
|
||||
]
|
||||
) === false) {
|
||||
return new NormalCommand();
|
||||
}
|
||||
|
||||
return new NoopCommand();
|
||||
}
|
||||
}
|
||||
@ -28,93 +28,3 @@ final class GildedRose
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface Command
|
||||
{
|
||||
public function execute(Item $item): void;
|
||||
}
|
||||
|
||||
final class CommandFactory
|
||||
{
|
||||
private const SULFURAS_HAND_OF_RAGNAROS = 'Sulfuras, Hand of Ragnaros';
|
||||
private const BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT = 'Backstage passes to a TAFKAL80ETC concert';
|
||||
private const AGED_BRIE = 'Aged Brie';
|
||||
|
||||
public function createFor(string $itemName): Command
|
||||
{
|
||||
if ($itemName === self::AGED_BRIE) {
|
||||
return new AgedBrieCommand();
|
||||
}
|
||||
|
||||
if ($itemName === self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT) {
|
||||
return new BackstageCommand();
|
||||
}
|
||||
|
||||
if (in_array($itemName,
|
||||
[
|
||||
self::AGED_BRIE,
|
||||
self::BACKSTAGE_PASSES_TO_A_TAFKAL_80_ETC_CONCERT,
|
||||
self::SULFURAS_HAND_OF_RAGNAROS
|
||||
]
|
||||
) === false) {
|
||||
return new NormalCommand();
|
||||
}
|
||||
|
||||
return new NoopCommand();
|
||||
}
|
||||
}
|
||||
|
||||
final class AgedBrieCommand implements Command
|
||||
{
|
||||
public function execute(Item $item): void
|
||||
{
|
||||
$item->decreaseSellDate();
|
||||
|
||||
$item->increaseQuality();
|
||||
if ($item->isSellDatePassed()) {
|
||||
$item->increaseQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class BackstageCommand implements Command
|
||||
{
|
||||
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 implements Command
|
||||
{
|
||||
public function execute(Item $item): void
|
||||
{
|
||||
$item->decreaseSellDate();
|
||||
$item->decreaseQuality();
|
||||
if ($item->isSellDatePassed()) {
|
||||
$item->decreaseQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class NoopCommand implements Command
|
||||
{
|
||||
public function execute(Item $item): void
|
||||
{
|
||||
// noop
|
||||
}
|
||||
}
|
||||
13
php/src/NoopCommand.php
Normal file
13
php/src/NoopCommand.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GildedRose;
|
||||
|
||||
final class NoopCommand implements Command
|
||||
{
|
||||
public function execute(Item $item): void
|
||||
{
|
||||
// noop
|
||||
}
|
||||
}
|
||||
17
php/src/NormalCommand.php
Normal file
17
php/src/NormalCommand.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GildedRose;
|
||||
|
||||
final class NormalCommand implements Command
|
||||
{
|
||||
public function execute(Item $item): void
|
||||
{
|
||||
$item->decreaseSellDate();
|
||||
$item->decreaseQuality();
|
||||
if ($item->isSellDatePassed()) {
|
||||
$item->decreaseQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user