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;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
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,60 +2,42 @@
|
||||
|
||||
namespace App;
|
||||
|
||||
final class GildedRose {
|
||||
class GildedRose
|
||||
{
|
||||
|
||||
private $items = [];
|
||||
|
||||
public function __construct($items) {
|
||||
public function __construct($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) {
|
||||
if($item->name == 'Aged Brie'){
|
||||
$item->quality += 1;
|
||||
switch ($item->name) {
|
||||
case $agedBrieName:
|
||||
$agedBried = new AgedBried($item);
|
||||
$agedBried->updateQuality();
|
||||
return;
|
||||
|
||||
if ($item->sell_in <= 0) {
|
||||
$item->quality += 1;
|
||||
}
|
||||
case $backstageName:
|
||||
$backstagePasses = new BackstagePasses($item);
|
||||
$backstagePasses->updateQuality();
|
||||
return;
|
||||
|
||||
if ($item->quality > 50) {
|
||||
$item->quality = 50;
|
||||
}
|
||||
|
||||
$item->sell_in -= 1;
|
||||
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;
|
||||
case $sulfarasName:
|
||||
$sulfaras = new Sulfaras($item);
|
||||
$sulfaras->updateQuality();
|
||||
return;
|
||||
default:
|
||||
$defoultItem = new DefaultItem($item);
|
||||
$defoultItem->updateQuality();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,15 @@
|
||||
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