Download the PHP package prodigeris/php-gilded-rose-refactoring-kata without Composer
On this page you can find all versions of the php package prodigeris/php-gilded-rose-refactoring-kata. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download prodigeris/php-gilded-rose-refactoring-kata
More information about prodigeris/php-gilded-rose-refactoring-kata
Files in prodigeris/php-gilded-rose-refactoring-kata
Package php-gilded-rose-refactoring-kata
Short Description My PHP solution to GildedRose Refactoring Kata.
License MIT
Informations about the package php-gilded-rose-refactoring-kata
Requirements
php: 7.1 or above
Installation
composer require prodigeris/php-gilded-rose-refactoring-kata
Usage
If you are not using containers:
Tests
Just run phpunit
to execute all the tests.
Description
This is my PHP solution to Gilded Rose Refactoring Kata by Terry Hughes.
It was quite a fun; I have managed to use a couple of design patterns.
- Abstract Factory Pattern to build
Products
(implementations ofItems
) - Decorator Pattern for
Products
to modifyItem
values. - Command Pattern to modify
Item
values according to rules.
Product
Everything about the Product
can be set dynamically.
- Traits
HasDayRangeMultiplier
. If the quality of the product changes differently over time. Used by default.Expires
. If the quality of the product goes to zero after the sale date. (e.g.BackstagePass
)
- Properties
- const
name
. The name by whichProductFactory
identifies theProduct
. Default:empty
max_quality
. Determines max value of the quality. Default:50
min_quality
. Determines min value of the quality. Default:0
quality_step
. Determines the direction and speed of quality change over time. Default:-1
day_range_multiplier
. Determines how quality acts depending on the days. Default:[0 => 2]
which means that after the sale date the quality step is twice as large.
- const
- Public methods
update
. UpdatesItem
for the new day.getItem
. ReturnsItem
assigned to the product.getMaxQuality
getMinQuality
getQualityStep
. Returns the quality step taking multipliers in mind.getNewQuality
. Returns the quality for the next day. Warning: It does not take rules in mind. Rules are checked on property change.isAfterSale
. Returns if the product has passed the sale date
New Product
If you want to introduce a new product, first create a class in Products
directory.
E.g.
Then register in the container of ProductFactoryRegistry
.
Voilà!