mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
R-02 Added additional classes
This commit is contained in:
parent
523c894eb1
commit
bd3dd7b791
46
php/src/FirstProcessingRule.php
Normal file
46
php/src/FirstProcessingRule.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace GildedRose;
|
||||||
|
|
||||||
|
use GildedRose\Item;
|
||||||
|
|
||||||
|
class FirstProcessingRule
|
||||||
|
{
|
||||||
|
private $item;
|
||||||
|
|
||||||
|
public function __construct(Item $item)
|
||||||
|
{
|
||||||
|
$this->item = $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function firstProcessingRule()
|
||||||
|
{
|
||||||
|
$item = $this->item;
|
||||||
|
|
||||||
|
if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
|
if ($item->quality > 0) {
|
||||||
|
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
|
||||||
|
$item->quality = $item->quality - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($item->quality < 50) {
|
||||||
|
$item->quality = $item->quality + 1;
|
||||||
|
if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
|
if ($item->sell_in < 11) {
|
||||||
|
if ($item->quality < 50) {
|
||||||
|
$item->quality = $item->quality + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($item->sell_in < 6) {
|
||||||
|
if ($item->quality < 50) {
|
||||||
|
$item->quality = $item->quality + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -4,9 +4,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GildedRose;
|
namespace GildedRose;
|
||||||
|
|
||||||
use GildedRose\GildedRoseInterface;
|
|
||||||
|
|
||||||
final class GildedRose implements GildedRoseInterface
|
final class GildedRose
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Item[]
|
* @var Item[]
|
||||||
@ -22,68 +21,17 @@ final class GildedRose implements GildedRoseInterface
|
|||||||
{
|
{
|
||||||
foreach ($this->items as $item) {
|
foreach ($this->items as $item) {
|
||||||
|
|
||||||
$this->firstProcessingRule($item);
|
$firstItem = new FirstProcessingRule($item);
|
||||||
|
|
||||||
$this->secondProcessingRule($item);
|
$firstItem->firstProcessingRule();
|
||||||
|
|
||||||
$this->thirdProcessingRule($item);
|
$secondItem = new SecondProcessingRule($item);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function firstProcessingRule(&$item)
|
$secondItem->secondProcessingRule();
|
||||||
{
|
|
||||||
|
|
||||||
if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') {
|
$thirdItem = new ThirdProcessingRule($item);
|
||||||
if ($item->quality > 0) {
|
|
||||||
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
|
|
||||||
$item->quality = $item->quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($item->quality < 50) {
|
|
||||||
$item->quality = $item->quality + 1;
|
|
||||||
if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') {
|
|
||||||
if ($item->sell_in < 11) {
|
|
||||||
if ($item->quality < 50) {
|
|
||||||
$item->quality = $item->quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($item->sell_in < 6) {
|
|
||||||
if ($item->quality < 50) {
|
|
||||||
$item->quality = $item->quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function secondProcessingRule(&$item)
|
$thirdItem->thirdProcessingRule();
|
||||||
{
|
|
||||||
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
|
|
||||||
$item->sell_in = $item->sell_in - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function thirdProcessingRule(&$item)
|
|
||||||
{
|
|
||||||
if ($item->sell_in < 0) {
|
|
||||||
if ($item->name != 'Aged Brie') {
|
|
||||||
if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') {
|
|
||||||
if ($item->quality > 0) {
|
|
||||||
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
|
|
||||||
$item->quality = $item->quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$item->quality = $item->quality - $item->quality;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($item->quality < 50) {
|
|
||||||
$item->quality = $item->quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace GildedRose;
|
|
||||||
|
|
||||||
use GildedRose\Item;
|
|
||||||
|
|
||||||
interface GildedRoseInterface
|
|
||||||
{
|
|
||||||
public function updateQuality();
|
|
||||||
|
|
||||||
public function firstProcessingRule(Item &$item);
|
|
||||||
|
|
||||||
public function secondProcessingRule(Item &$item);
|
|
||||||
|
|
||||||
public function thirdProcessingRule(Item &$item);
|
|
||||||
|
|
||||||
}
|
|
||||||
24
php/src/SecondProcessingRule.php
Normal file
24
php/src/SecondProcessingRule.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace GildedRose;
|
||||||
|
|
||||||
|
|
||||||
|
class SecondProcessingRule
|
||||||
|
{
|
||||||
|
public function __construct(Item $item)
|
||||||
|
{
|
||||||
|
$this->item = $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function secondProcessingRule()
|
||||||
|
{
|
||||||
|
$item = $this->item;
|
||||||
|
|
||||||
|
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
|
||||||
|
$item->sell_in = $item->sell_in - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
37
php/src/ThirdProcessingRule.php
Normal file
37
php/src/ThirdProcessingRule.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace GildedRose;
|
||||||
|
|
||||||
|
|
||||||
|
class ThirdProcessingRule
|
||||||
|
{
|
||||||
|
public function __construct(Item $item)
|
||||||
|
{
|
||||||
|
$this->item = $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function thirdProcessingRule()
|
||||||
|
{
|
||||||
|
$item = $this->item;
|
||||||
|
|
||||||
|
if ($item->sell_in < 0) {
|
||||||
|
if ($item->name != 'Aged Brie') {
|
||||||
|
if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
|
if ($item->quality > 0) {
|
||||||
|
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
|
||||||
|
$item->quality = $item->quality - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$item->quality = $item->quality - $item->quality;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($item->quality < 50) {
|
||||||
|
$item->quality = $item->quality + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user