Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 33 |
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 |
||
57 | public function testFlatToNestedMultiRootNode() |
||
58 | { |
||
59 | $flatTree = [ |
||
60 | [ |
||
61 | 'id' => '1', |
||
62 | 'parent' => null, |
||
63 | 'level' => 1, |
||
64 | ], |
||
65 | [ |
||
66 | 'id' => '1.2', |
||
67 | 'parent' => '1', |
||
68 | 'level' => 2, |
||
69 | ], |
||
70 | [ |
||
71 | 'id' => '2', |
||
72 | 'parent' => null, |
||
73 | 'level' => 1, |
||
74 | ], |
||
75 | [ |
||
76 | 'id' => '2.1', |
||
77 | 'parent' => '2', |
||
78 | 'level' => 2, |
||
79 | ], |
||
80 | ]; |
||
81 | $result = Utilities::flatToNested($flatTree); |
||
82 | |||
83 | $this->assertEquals( |
||
84 | [ |
||
85 | [ |
||
86 | 'id' => '1', |
||
87 | 'parent' => null, |
||
88 | 'level' => 1, |
||
89 | '_children' => [ |
||
90 | [ |
||
91 | 'id' => '1.2', |
||
92 | 'parent' => '1', |
||
93 | 'level' => 2, |
||
94 | '_children' => [], |
||
95 | ], |
||
96 | ], |
||
97 | ], |
||
98 | [ |
||
99 | 'id' => '2', |
||
100 | 'parent' => null, |
||
101 | 'level' => 1, |
||
102 | '_children' => [ |
||
103 | [ |
||
104 | 'id' => '2.1', |
||
105 | 'parent' => '2', |
||
106 | 'level' => 2, |
||
107 | '_children' => [], |
||
108 | ], |
||
109 | ], |
||
110 | ], |
||
111 | ], $result); |
||
112 | } |
||
113 | |||
308 |