1 | <?php |
||
5 | class GildedRose |
||
6 | { |
||
7 | |||
8 | private $items; |
||
9 | |||
10 | 14 | function __construct($items) |
|
14 | |||
15 | 14 | function update_quality() |
|
16 | { |
||
17 | 14 | foreach ($this->items as $item) |
|
18 | { |
||
19 | 14 | $new_item = $this->factory_method($item); |
|
20 | |||
21 | 14 | if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') |
|
22 | { |
||
23 | 7 | $this->decrementQualityOneUnitIfItemNameIsNotSulfuras($item); |
|
24 | } |
||
25 | else |
||
26 | { |
||
27 | 7 | $this->incrementQuality($item); |
|
28 | } |
||
29 | |||
30 | if ($item->name != 'Sulfuras, Hand of Ragnaros') |
||
31 | { |
||
32 | $item->sell_in = $item->sell_in - 1; |
||
33 | } |
||
34 | |||
35 | if ($item->sell_in > 0) |
||
36 | { |
||
37 | continue; |
||
38 | } |
||
39 | |||
40 | if ($item->name == 'Aged Brie') |
||
41 | { |
||
42 | $this->increaseQualityByOneUnitWhenQualitySmallerThanFifty($item); |
||
43 | } |
||
44 | |||
45 | if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') |
||
46 | { |
||
47 | $this->decrementQualityOneUnitIfItemNameIsNotSulfuras($item); |
||
48 | } |
||
49 | else |
||
50 | { |
||
51 | $item->quality = $item->quality - $item->quality; |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | |||
56 | 3 | public function increaseQualityByOneUnitWhenQualitySmallerThanFifty($item): void |
|
63 | |||
64 | 7 | public function decrementQualityOneUnitIfItemNameIsNotSulfuras($item): void |
|
65 | { |
||
66 | 7 | if ($item->quality > 0) |
|
67 | { |
||
68 | 5 | if ($item->name != 'Sulfuras, Hand of Ragnaros') |
|
69 | { |
||
70 | 3 | $item->quality = $item->quality - 1; |
|
71 | } |
||
72 | } |
||
73 | 7 | } |
|
74 | |||
75 | 7 | public function incrementQuality($item): void |
|
91 | |||
92 | 4 | private function incrementQualityForBackstagePasses($item): void |
|
103 | |||
104 | 14 | private function factory_method($item) |
|
123 | } |
||
124 | |||
125 | |||
126 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.