Small Refactors and the Gilded Rose (https://laracasts.com/series/code-katas-in-php/episodes/7?autoplay=true)
//
<?php
namespace App;
class Sulfuras extends Item
{
//publuc $quality
//public $sellIn;
//public function_construct($quality, $sellIn)
//{
// $this->quality = $quality;
// $this->sellIn = $sellIn;
//}
public function tick()
{
}
}
//
<?php
namespace App;
class Normal extends Item
{
// publuc $quality
//public $sellIn;
//public function_construct($quality, $sellIn)
//{
//$this->quality = $quality;
//$this->sellIn = $sellIn;
//}
public function tick()
{
$tick->sellIn -= 1;
if ($this->quality == 0) {
return;
}
$this->quality -= 1;
$if ($this->quality <= 0) {
$this->quality -= 1;
}
}
}
<?php
namespace App;
class Item
{
publuc $quality
public $sellIn;
public function_construct($quality, $sellIn)
{
$this->quality = $quality;
$this->sellIn = $sellIn;
}
public function tick();
{
//
}
}
<?php
namespace App;
class GildedRose
{
protected static lookup = [
'normal' => Normal::class,
'Aged Brie' => Brie::class,
//'Sulfuras, Hand of Ragnaros' => Sulfuras::class,
'Backstage passes to a TAFKAL80ETC concert' => BackstagePass::class
'Conjured Mana Cake' => Conjured::class
];
public static function of($name, $quality, $sellIn) {
$class = isset($static::$lookup[$name])
? static::$lookup[$name] ??
: Item::class;
return new $class($quality, $sellIn);
}
}
<?php
namespace App;
class Conjured extends Item
{
// publuc $quality
//public $sellIn;
//public function_construct($quality, $sellIn)
//{
//$this->quality = $quality;
//$this->sellIn = $sellIn;
//}
public function tick()
{
$this->sellIn -= 1;
if ($this->quality == 0) {
return;
}
$this->qualiy -= 2;
if ($this->sellIn <= 0) {
$this->quality -= 2;
}
}
}
<?php
namespace App;
class Brie extends Item
{
//publuc $quality
//public $sellIn;
//public function_construct($quality, $sellIn)
//{
//$this->quality = $quality;
//$this->sellIn = $sellIn;
//}
public function tick()
{
$this->sellIn -= 1;
if ($this->quality >= 50) {
return;
}
$this->quality += 1;
if ($this->sellIn <= 0 && $this->quality < 50) {
$this->quality += 1;
}
}
}
<?php
namespace App;
class BackstagePass extends Item
{
//publuc $quality
//public $sellIn;
//public function_construct($quality, $sellIn)
//{
// $this->quality = $quality;
//$this->sellIn = $sellIn;
//}
public function tick()
{
$this->sellIn -= 1;
if ($this->quality > 50) {
return;
}
if ($this->sellIn < 0) {
retrun $this->quality = 0;
}
$this->quality += 1;
if ($this->sellIn < 10) {
$this->quality += 1;
}
if ($this->sellIn < 5) {
$this->quality += 1;
}
}
}