Conditions | 1 |
Total Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
190 | public function testMoreComplexEmbeddedRule(): void |
||
191 | { |
||
192 | $dataSet = new ObjectDataSet(new Chart()); |
||
193 | $secondEmbeddedRules = [ |
||
194 | 'x' => [new Number(min: -10, max: 10)], |
||
195 | 'y' => [new Number(min: -10, max: 10)], |
||
196 | ]; |
||
197 | $firstEmbeddedRules = [ |
||
198 | 'coordinates' => new Nested( |
||
199 | $secondEmbeddedRules, |
||
200 | requirePropertyPath: true, |
||
201 | noPropertyPathMessage: 'Custom message 4.' |
||
202 | ), |
||
203 | 'rgb' => [ |
||
204 | new Count(exactly: 3), |
||
205 | new Each( |
||
206 | [new Number(min: 0, max: 255)], |
||
207 | incorrectInputMessage: 'Custom message 5.', |
||
208 | ), |
||
209 | ], |
||
210 | ]; |
||
211 | |||
212 | $actualRules = $this->toNestedArray($dataSet->getRules()); |
||
213 | |||
214 | // check Chart structure has right structure |
||
215 | $this->assertIsArray($actualRules); |
||
216 | $this->assertArrayHasKey('points', $actualRules); |
||
217 | $this->assertCount(1, $actualRules = $this->toArray($actualRules['points'])); |
||
218 | $this->assertInstanceOf(Each::class, $actualRules[0]); |
||
219 | |||
220 | // check Chart structure has right structure |
||
221 | $actualFirstEmbeddedRules = $this->toArray($actualRules[0]->getRules()); |
||
222 | $this->assertIsArray($actualFirstEmbeddedRules); |
||
223 | $this->assertCount(1, $actualFirstEmbeddedRules); |
||
224 | $this->assertInstanceOf(Nested::class, $actualFirstEmbeddedRules[0]); |
||
225 | |||
226 | // check Point structure has right structure |
||
227 | $innerRules = $this->toArray($actualFirstEmbeddedRules[0]->getRules()); |
||
228 | // rgb has usual structure. We can check as is |
||
229 | $this->assertEquals($firstEmbeddedRules['rgb'], $this->toArray($innerRules['rgb'])); |
||
230 | |||
231 | // coordinates has embedded structure, so we need to unpack rules before check it |
||
232 | $this->assertIsArray($innerRules = $this->toArray($innerRules['coordinates'])); |
||
233 | $this->assertCount(1, $innerRules); |
||
234 | $this->assertInstanceOf(Each::class, $innerRules[0]); |
||
235 | |||
236 | $secondInnerRules = $this->toArray($innerRules[0]->getRules()); |
||
237 | $this->assertIsArray($secondInnerRules); |
||
238 | $this->assertCount(1, $secondInnerRules); |
||
239 | $this->assertInstanceOf(Nested::class, $secondInnerRules[0]); |
||
240 | $this->assertEquals($secondEmbeddedRules, $this->toNestedArray($secondInnerRules[0]->getRules())); |
||
241 | } |
||
258 |