mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
separate into classes
This commit is contained in:
parent
e6e459351d
commit
ea61ae5c8d
@ -4,7 +4,26 @@
|
|||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
|
|
||||||
class AgedBried
|
class AgedBried extends GildedRose
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private $item;
|
||||||
|
|
||||||
|
public function __construct($item) {
|
||||||
|
$this->item = $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateQuality(){
|
||||||
|
$this->item->quality += 1;
|
||||||
|
|
||||||
|
if ($this->item->sell_in <= 0) {
|
||||||
|
$this->item->quality += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->item->quality > 50) {
|
||||||
|
$this->item->quality = 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->item->sell_in -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -4,7 +4,28 @@
|
|||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
|
|
||||||
class BackstagePasses
|
class BackstagePasses extends GildedRose
|
||||||
{
|
{
|
||||||
|
private $item;
|
||||||
|
|
||||||
|
public function __construct($item) {
|
||||||
|
$this->item = $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateQuality(){
|
||||||
|
$this->item->quality += 1;
|
||||||
|
if ($this->item->sell_in <= 10) {
|
||||||
|
$this->item->quality += 1;
|
||||||
|
}
|
||||||
|
if ($this->item->sell_in <= 5) {
|
||||||
|
$this->item->quality += 1;
|
||||||
|
}
|
||||||
|
if ($this->item->quality > 50) {
|
||||||
|
$this->item->quality = 50;
|
||||||
|
}
|
||||||
|
if ($this->item->sell_in <= 0) {
|
||||||
|
$this->item->quality = 0;
|
||||||
|
}
|
||||||
|
$this->item->sell_in -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -2,61 +2,43 @@
|
|||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
final class GildedRose {
|
class GildedRose
|
||||||
|
{
|
||||||
|
|
||||||
private $items = [];
|
private $items = [];
|
||||||
|
|
||||||
public function __construct($items) {
|
public function __construct($items)
|
||||||
|
{
|
||||||
$this->items = $items;
|
$this->items = $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateQuality() {
|
public function updateQuality()
|
||||||
|
{
|
||||||
|
$agedBrieName = 'Aged Brie';
|
||||||
|
$backstageName = 'Backstage passes to a TAFKAL80ETC concert';
|
||||||
|
$sulfarasName = 'Sulfuras, Hand of Ragnaros';
|
||||||
|
|
||||||
foreach ($this->items as $item) {
|
foreach ($this->items as $item) {
|
||||||
if($item->name == 'Aged Brie'){
|
switch ($item->name) {
|
||||||
$item->quality += 1;
|
case $agedBrieName:
|
||||||
|
$agedBried = new AgedBried($item);
|
||||||
|
$agedBried->updateQuality();
|
||||||
|
return;
|
||||||
|
|
||||||
if ($item->sell_in <= 0) {
|
case $backstageName:
|
||||||
$item->quality += 1;
|
$backstagePasses = new BackstagePasses($item);
|
||||||
}
|
$backstagePasses->updateQuality();
|
||||||
|
return;
|
||||||
|
|
||||||
if ($item->quality > 50) {
|
case $sulfarasName:
|
||||||
$item->quality = 50;
|
$sulfaras = new Sulfaras($item);
|
||||||
}
|
$sulfaras->updateQuality();
|
||||||
|
return;
|
||||||
$item->sell_in -= 1;
|
default:
|
||||||
|
$defoultItem = new DefaultItem($item);
|
||||||
|
$defoultItem->updateQuality();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if($item->name == 'Backstage passes to a TAFKAL80ETC concert'){
|
|
||||||
$item->quality += 1;
|
|
||||||
if ($item->sell_in <= 10) {
|
|
||||||
$item->quality += 1;
|
|
||||||
}
|
|
||||||
if ($item->sell_in <= 5) {
|
|
||||||
$item->quality += 1;
|
|
||||||
}
|
|
||||||
if ($item->quality > 50) {
|
|
||||||
$item->quality = 50;
|
|
||||||
}
|
|
||||||
if ($item->sell_in <= 0) {
|
|
||||||
$item->quality = 0;
|
|
||||||
}
|
|
||||||
$item->sell_in -= 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if ($item->name == 'Sulfuras, Hand of Ragnaros') {
|
|
||||||
$item->quality = 80;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
$item->quality -= 1;
|
|
||||||
if ($item->sell_in <= 0) {
|
|
||||||
$item->quality -= 1;
|
|
||||||
}
|
|
||||||
$item->sell_in -= 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,15 @@
|
|||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
|
|
||||||
class Sulfaras
|
class Sulfaras extends GildedRose
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private $item;
|
||||||
|
|
||||||
|
public function __construct($item) {
|
||||||
|
$this->item = $item;
|
||||||
|
}
|
||||||
|
public function updateQuality(){
|
||||||
|
$this->item->quality = 80;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user