mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Refactoring using solid and add Conjured item
This commit is contained in:
parent
214e49591f
commit
a7abaafa02
@ -3,6 +3,7 @@
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use App\GildedRose;
|
||||
use App\GildedRoseProductsService;
|
||||
use App\Item;
|
||||
|
||||
echo "OMGHAI!\n";
|
||||
@ -17,10 +18,12 @@ $items = array(
|
||||
new Item('Backstage passes to a TAFKAL80ETC concert', 10, 49),
|
||||
new Item('Backstage passes to a TAFKAL80ETC concert', 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item('Conjured Mana Cake', 3, 6)
|
||||
new Item('Conjured Mana Cake', 3, 6),
|
||||
new Item('Conjured Mana Cake', 3, -1)
|
||||
);
|
||||
|
||||
$app = new GildedRose($items);
|
||||
$gildedRose = new GildedRose($items);
|
||||
$app = new GildedRoseProductsService($gildedRose);
|
||||
|
||||
$days = 2;
|
||||
if (count($argv) > 1) {
|
||||
|
||||
@ -2,49 +2,36 @@
|
||||
|
||||
namespace App;
|
||||
|
||||
final class GildedRose {
|
||||
final class GildedRose implements GildedRoseInterface {
|
||||
|
||||
const AGED_BRIE = 'Aged Brie';
|
||||
const BACKSTAGE_PASS = 'Backstage passes to a TAFKAL80ETC concert';
|
||||
const SULFULRAS_RAGNAROS = 'Sulfuras, Hand of Ragnaros';
|
||||
const CONJURED = 'Conjured Mana Cake';
|
||||
const SELL_IN_ZERO = 0;
|
||||
const QUALITY_ZERO = 0;
|
||||
const QUALITY_MID = 11;
|
||||
const QUALITY_LOW = 6;
|
||||
const QUALITY_MAX = 50;
|
||||
|
||||
private $items = [];
|
||||
|
||||
|
||||
public function __construct($items) {
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
public function updateQuality() {
|
||||
foreach ($this->items as $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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
|
||||
$item->sell_in = $item->sell_in - 1;
|
||||
}
|
||||
|
||||
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') {
|
||||
public function getItems(){
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
public function checkQualityExceptSulfurasWhereSellInZero(Item $item)
|
||||
{
|
||||
if ($item->sell_in < self::SELL_IN_ZERO) {
|
||||
if ($item->name != self::AGED_BRIE) {
|
||||
if ($item->name != self::BACKSTAGE_PASS) {
|
||||
if ($item->quality > self::QUALITY_ZERO) {
|
||||
if ($item->name != self::SULFULRAS_RAGNAROS) {
|
||||
$item->quality = $item->quality - 1;
|
||||
}
|
||||
}
|
||||
@ -52,12 +39,51 @@ final class GildedRose {
|
||||
$item->quality = $item->quality - $item->quality;
|
||||
}
|
||||
} else {
|
||||
if ($item->quality < 50) {
|
||||
if ($item->quality < self::QUALITY_MAX) {
|
||||
$item->quality = $item->quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function checkQualityExeceptSulfurasForBrieAndPassProducts(Item $item) {
|
||||
if (!($item->name != GildedRose::AGED_BRIE and $item->name != GildedRose::BACKSTAGE_PASS)) {
|
||||
if ($item->quality < self::QUALITY_MAX) {
|
||||
$item->quality = $item->quality + 1;
|
||||
if ($item->name == self::BACKSTAGE_PASS) {
|
||||
if ($item->sell_in < self::QUALITY_MID) {
|
||||
$item->quality = $item->quality + 1;
|
||||
}
|
||||
if ($item->sell_in < self::QUALITY_LOW) {
|
||||
$item->quality = $item->quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function checkQualityLessThanZeroExceptSulfuras(Item $item){
|
||||
if ($item->name != GildedRose::AGED_BRIE and $item->name != GildedRose::BACKSTAGE_PASS) {
|
||||
if ($item->quality > self::QUALITY_ZERO) {
|
||||
if ($item->name != self::SULFULRAS_RAGNAROS) {
|
||||
if($item->name == self::CONJURED) {
|
||||
$item->quality = ($item->quality == 1) ? $item->quality - 1 : $item->quality - 2;
|
||||
}else {
|
||||
$item->quality = $item->quality - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function reduceSellInExceptSulfuras(Item $item){
|
||||
//reduce sellin
|
||||
if ($item->name != self::SULFULRAS_RAGNAROS) {
|
||||
$item->sell_in = $item->sell_in - 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
16
php7/src/GildedRoseInterface.php
Normal file
16
php7/src/GildedRoseInterface.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
interface GildedRoseInterface {
|
||||
|
||||
public function checkQualityExceptSulfurasWhereSellInZero(Item $item);
|
||||
|
||||
public function checkQualityExeceptSulfurasForBrieAndPassProducts(Item $item);
|
||||
|
||||
public function checkQualityLessThanZeroExceptSulfuras(Item $item);
|
||||
|
||||
public function reduceSellInExceptSulfuras(Item $item);
|
||||
|
||||
|
||||
}
|
||||
21
php7/src/GildedRoseProductsService.php
Normal file
21
php7/src/GildedRoseProductsService.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
class GildedRoseProductsService {
|
||||
|
||||
public $GildedRose;
|
||||
public function __construct(GildedRoseInterface $gildedRose) {
|
||||
$this->GildedRose = $gildedRose;
|
||||
}
|
||||
|
||||
public function updateQuality() {
|
||||
|
||||
foreach ($this->GildedRose->getItems() as $item) {
|
||||
$this->GildedRose->checkQualityLessThanZeroExceptSulfuras($item);
|
||||
$this->GildedRose->checkQualityExeceptSulfurasForBrieAndPassProducts($item);
|
||||
$this->GildedRose->reduceSellInExceptSulfuras($item);
|
||||
$this->GildedRose->checkQualityExceptSulfurasWhereSellInZero($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user