GildedRose-Refactoring-Kata/php/src/GildedRose.php
naciriii 66867fbe7a refactor: set global architecture and refactor code
- Create an Ioc container and set factories and services
- Adjust degrading Strategies
- Clean up and do global chores here and there and avoid Dry code
- Write unit and integration tests and ensure correct business logic
2022-03-30 05:34:47 +01:00

44 lines
1001 B
PHP

<?php
declare(strict_types=1);
namespace GildedRose;
use GildedRose\Services\AbstractDegradingStrategyFactory;
final class GildedRose
{
/**
* @var Item[]
*/
private $items;
/**
* Degrading Strategy Factory
* @var AbstractDegradingStrategyFactory
*/
private $degradingStrategyFactory;
public function __construct(array $items, AbstractDegradingStrategyFactory $degradingStrategyFactory)
{
$this->items = $items;
$this->degradingStrategyFactory = $degradingStrategyFactory;
}
public function __get($name)
{
return property_exists($this, $name) ? $this->{$name} : null;
}
/**
* Handle Updating quality in cleaner way respecting multiple software engineering principles
* Such as Solid/Dry etc
*/
public function updateQuality(): void
{
foreach ($this->items as $item) {
$this->degradingStrategyFactory->getDegradingStrategy($item)->handle();
}
}
}