Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 34 |
Lines | 0 |
Ratio | 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 |
||
15 | public function testIt() |
||
16 | { |
||
17 | $formData = [ |
||
18 | 'names' => [ |
||
19 | 'Jane', |
||
20 | 'Bob', |
||
21 | 'Mary', |
||
22 | ], |
||
23 | 'emails' => [ |
||
24 | '[email protected]', |
||
25 | '[email protected]', |
||
26 | '[email protected]', |
||
27 | ], |
||
28 | 'occupations' => [ |
||
29 | 'Doctor', |
||
30 | 'Plumber', |
||
31 | 'Dentist', |
||
32 | ], |
||
33 | ]; |
||
34 | |||
35 | //Must take and return a Collection |
||
36 | $transpose = function (Collection $collections) { |
||
37 | $transposed = array_map( |
||
38 | function (...$items) { |
||
39 | return $items; |
||
40 | }, |
||
41 | ...$collections->values()->toArray() |
||
42 | ); |
||
43 | |||
44 | return Collection::from($transposed); |
||
45 | }; |
||
46 | |||
47 | $result = Collection::from($formData) |
||
48 | ->transform($transpose) |
||
49 | ->toArray(); |
||
50 | |||
51 | $expected = [ |
||
52 | [ |
||
53 | 'Jane', |
||
54 | '[email protected]', |
||
55 | 'Doctor' |
||
56 | ], |
||
57 | [ |
||
58 | 'Bob', |
||
59 | '[email protected]', |
||
60 | 'Plumber' |
||
61 | ], |
||
62 | [ |
||
63 | 'Mary', |
||
64 | '[email protected]', |
||
65 | 'Dentist' |
||
66 | ] |
||
67 | ]; |
||
68 | |||
69 | $this->assertEquals($expected, $result); |
||
70 | } |
||
71 | } |
||
72 |