1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kata\GildedRoseKata; |
4
|
|
|
|
5
|
|
|
class GildedRose { |
6
|
|
|
|
7
|
|
|
private $items; |
8
|
|
|
|
9
|
1 |
|
function __construct($items) { |
|
|
|
|
10
|
1 |
|
$this->items = $items; |
11
|
1 |
|
} |
12
|
|
|
|
13
|
1 |
|
function update_quality() { |
|
|
|
|
14
|
1 |
|
foreach ($this->items as $item) { |
15
|
1 |
|
if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') { |
|
|
|
|
16
|
1 |
|
if ($item->quality > 0) { |
17
|
|
|
if ($item->name != 'Sulfuras, Hand of Ragnaros') { |
18
|
1 |
|
$item->quality = $item->quality - 1; |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
} else { |
22
|
|
|
if ($item->quality < 50) { |
23
|
|
|
$item->quality = $item->quality + 1; |
24
|
|
|
if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') { |
25
|
|
|
if ($item->sell_in < 11) { |
26
|
|
|
if ($item->quality < 50) { |
27
|
|
|
$item->quality = $item->quality + 1; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
if ($item->sell_in < 6) { |
31
|
|
|
if ($item->quality < 50) { |
32
|
|
|
$item->quality = $item->quality + 1; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
1 |
|
if ($item->name != 'Sulfuras, Hand of Ragnaros') { |
40
|
1 |
|
$item->sell_in = $item->sell_in - 1; |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
if ($item->sell_in < 0) { |
44
|
1 |
|
if ($item->name != 'Aged Brie') { |
45
|
1 |
|
if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') { |
46
|
1 |
|
if ($item->quality > 0) { |
47
|
|
|
if ($item->name != 'Sulfuras, Hand of Ragnaros') { |
48
|
1 |
|
$item->quality = $item->quality - 1; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} else { |
52
|
1 |
|
$item->quality = $item->quality - $item->quality; |
53
|
|
|
} |
54
|
|
|
} else { |
55
|
|
|
if ($item->quality < 50) { |
56
|
1 |
|
$item->quality = $item->quality + 1; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
1 |
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
|
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.