1 | <?php |
||||
2 | |||||
3 | namespace KuwashiroBuster\Kuwashiro; |
||||
4 | |||||
5 | use KuwashiroBuster\Constraints\CoverType; |
||||
6 | use KuwashiroBuster\Constraints\Generation; |
||||
7 | use KuwashiroBuster\Processor\ProcessorInterface; |
||||
8 | |||||
9 | class Kuwashiro implements KuwashiroInterface |
||||
10 | { |
||||
11 | /** |
||||
12 | * @var string |
||||
13 | */ |
||||
14 | protected $defaultProcessor = '\\KuwashiroBuster\\Processor\\Processor'; |
||||
15 | |||||
16 | /** |
||||
17 | * @var ProcessorInterface |
||||
18 | */ |
||||
19 | protected $processor; |
||||
20 | |||||
21 | /** |
||||
22 | * @var int |
||||
23 | */ |
||||
24 | public $coverType; |
||||
25 | |||||
26 | /** |
||||
27 | * @var bool |
||||
28 | */ |
||||
29 | public $sekisanEnabled; |
||||
30 | |||||
31 | /** |
||||
32 | * @var int 世代 |
||||
33 | */ |
||||
34 | protected $generation; |
||||
35 | |||||
36 | /** |
||||
37 | * @var int 現在の有効積算温度 |
||||
38 | */ |
||||
39 | protected $currentYukoSekisanOndo; |
||||
40 | |||||
41 | |||||
42 | /** |
||||
43 | * Kuwashiro constructor. |
||||
44 | * @param $generation |
||||
45 | * @param bool $enableSekisan |
||||
46 | */ |
||||
47 | public function __construct($generation, $enableSekisan = true) |
||||
48 | { |
||||
49 | if (!in_array($generation, Generation::getList())) { |
||||
50 | throw new \InvalidArgumentException(); |
||||
51 | } |
||||
52 | |||||
53 | $this->currentYukoSekisanOndo = 0; |
||||
54 | $this->coverType = CoverType::ROTEN; |
||||
55 | $this->processor(new $this->defaultProcessor); |
||||
56 | |||||
57 | $this->generation = $generation; |
||||
58 | $this->sekisanEnabled = $enableSekisan; |
||||
59 | } |
||||
60 | |||||
61 | /** |
||||
62 | * 世代を返す |
||||
63 | * |
||||
64 | * @return mixed |
||||
65 | */ |
||||
66 | public function getGeneration() |
||||
67 | { |
||||
68 | return $this->generation; |
||||
69 | } |
||||
70 | |||||
71 | /** |
||||
72 | * 孵化したかを返す |
||||
73 | * |
||||
74 | * @return bool |
||||
75 | */ |
||||
76 | public function isHatch() |
||||
77 | { |
||||
78 | return $this->getYukoSekisanOndo() < $this->getCurrentYukioSekisanOndo(); |
||||
79 | } |
||||
80 | |||||
81 | /** |
||||
82 | * 発育零点を返す |
||||
83 | * |
||||
84 | * @return float |
||||
85 | */ |
||||
86 | public function getHatsuikuZeroTen() |
||||
87 | { |
||||
88 | $hatsuikuZeroTens = $this->processor()->getHatsuikuZeroTens(); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
89 | return $hatsuikuZeroTens[$this->getGeneration()]; |
||||
90 | } |
||||
91 | |||||
92 | /** |
||||
93 | * 発育停止温度を返す |
||||
94 | * |
||||
95 | * @return float |
||||
96 | */ |
||||
97 | public function getHatsuikuTeishiOndo() |
||||
98 | { |
||||
99 | $hatsuikuTeishiOndos = $this->processor()->getHatsuikuTeishiOndos(); |
||||
0 ignored issues
–
show
The method
getHatsuikuTeishiOndos() does not exist on KuwashiroBuster\Processor\ProcessorInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to KuwashiroBuster\Processor\ProcessorInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
100 | return $hatsuikuTeishiOndos[$this->getGeneration()]; |
||||
101 | } |
||||
102 | |||||
103 | /** |
||||
104 | * 積算が有効化されているかを返す |
||||
105 | * |
||||
106 | * @return boolean |
||||
107 | */ |
||||
108 | public function isSekisanEnabled() |
||||
109 | { |
||||
110 | return $this->sekisanEnabled; |
||||
111 | } |
||||
112 | |||||
113 | /** |
||||
114 | * 気温で育つ |
||||
115 | * |
||||
116 | * @param $temperature |
||||
117 | * @return $this |
||||
118 | */ |
||||
119 | public function grow($temperature) |
||||
120 | { |
||||
121 | if ($this->isSekisanEnabled()) { |
||||
122 | $chakabuOndo = $this->processor()->toChakabunaiOndo($temperature, $this->getCoverType()); |
||||
123 | $this->currentYukoSekisanOndo += $this->processor()->toHiatariYukoOndo($chakabuOndo, $this->getGeneration()); |
||||
124 | } |
||||
125 | |||||
126 | return $this; |
||||
127 | } |
||||
128 | |||||
129 | /** |
||||
130 | * 現在の有効積算温度を返す |
||||
131 | * |
||||
132 | * @return float |
||||
133 | */ |
||||
134 | public function getCurrentYukioSekisanOndo() |
||||
135 | { |
||||
136 | return $this->currentYukoSekisanOndo; |
||||
137 | } |
||||
138 | |||||
139 | /** |
||||
140 | * 有効積算温度を返す |
||||
141 | * |
||||
142 | * @return float |
||||
143 | */ |
||||
144 | public function getYukoSekisanOndo() |
||||
145 | { |
||||
146 | $yukoSekisanOndos = $this->processor()->getYukoSekisanOndos(); |
||||
0 ignored issues
–
show
The method
getYukoSekisanOndos() does not exist on KuwashiroBuster\Processor\ProcessorInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to KuwashiroBuster\Processor\ProcessorInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
147 | return $yukoSekisanOndos[$this->getGeneration()]; |
||||
148 | } |
||||
149 | |||||
150 | /** |
||||
151 | * 積算を有効化する |
||||
152 | * |
||||
153 | * @param bool $enabled |
||||
154 | * @return $this |
||||
155 | */ |
||||
156 | public function enableSekisan($enabled = true) |
||||
157 | { |
||||
158 | $this->sekisanEnabled = $enabled; |
||||
159 | return $this; |
||||
160 | } |
||||
161 | |||||
162 | /** |
||||
163 | * @param \KuwashiroBuster\Processor\ProcessorInterface|null $processor |
||||
164 | * @return \KuwashiroBuster\Processor\ProcessorInterface |
||||
165 | */ |
||||
166 | protected function processor(\KuwashiroBuster\Processor\ProcessorInterface $processor = null) |
||||
167 | { |
||||
168 | if (!$this->processor instanceof \KuwashiroBuster\Processor\ProcessorInterface) { |
||||
0 ignored issues
–
show
|
|||||
169 | $this->processor = $processor; |
||||
170 | } |
||||
171 | |||||
172 | return $this->processor; |
||||
173 | } |
||||
174 | |||||
175 | /** |
||||
176 | * 被覆タイプを返す |
||||
177 | * |
||||
178 | * @return int |
||||
179 | */ |
||||
180 | public function getCoverType() |
||||
181 | { |
||||
182 | return $this->coverType; |
||||
183 | } |
||||
184 | |||||
185 | /** |
||||
186 | * 被覆タイプを設定する |
||||
187 | * |
||||
188 | * @param $coverType |
||||
189 | * @return $this |
||||
190 | */ |
||||
191 | public function setCoverType($coverType) |
||||
192 | { |
||||
193 | $this->coverType = $coverType; |
||||
194 | return $this; |
||||
195 | } |
||||
196 | } |