R-01 Add interface and create methods

This commit is contained in:
dashiwa 2020-12-31 16:00:48 +03:00
parent de2d37904a
commit 523c894eb1
2 changed files with 78 additions and 39 deletions

View File

@ -4,7 +4,9 @@ declare(strict_types=1);
namespace GildedRose; namespace GildedRose;
final class GildedRose use GildedRose\GildedRoseInterface;
final class GildedRose implements GildedRoseInterface
{ {
/** /**
* @var Item[] * @var Item[]
@ -19,51 +21,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 != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') {
if ($item->quality > 0) { $this->firstProcessingRule($item);
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
$item->quality = $item->quality - 1; $this->secondProcessingRule($item);
}
} $this->thirdProcessingRule($item);
} else { }
if ($item->quality < 50) { }
$item->quality = $item->quality + 1;
if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') { public function firstProcessingRule(&$item)
if ($item->sell_in < 11) { {
if ($item->quality < 50) {
$item->quality = $item->quality + 1; 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') {
if ($item->sell_in < 6) { $item->quality = $item->quality - 1;
if ($item->quality < 50) {
$item->quality = $item->quality + 1;
}
}
}
} }
} }
} else {
if ($item->name != 'Sulfuras, Hand of Ragnaros') { if ($item->quality < 50) {
$item->sell_in = $item->sell_in - 1; $item->quality = $item->quality + 1;
} if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') {
if ($item->sell_in < 11) {
if ($item->sell_in < 0) { if ($item->quality < 50) {
if ($item->name != 'Aged Brie') { $item->quality = $item->quality + 1;
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->sell_in < 6) {
if ($item->quality < 50) { if ($item->quality < 50) {
$item->quality = $item->quality + 1; $item->quality = $item->quality + 1;
}
} }
} }
} }
} }
} }
public function secondProcessingRule(&$item)
{
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;
}
}
}
}
} }

View File

@ -0,0 +1,18 @@
<?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);
}