mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-19 08:21:37 +00:00
- 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
44 lines
1001 B
PHP
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();
|
|
}
|
|
}
|
|
}
|