| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 62 | public function testFlatToNestedMultiRootNode() |
||
| 63 | { |
||
| 64 | $flatTree = array( |
||
| 65 | array( |
||
| 66 | 'id' => '1', |
||
| 67 | 'parent' => null, |
||
| 68 | 'level' => 1, |
||
| 69 | ), |
||
| 70 | array( |
||
| 71 | 'id' => '1.2', |
||
| 72 | 'parent' => '1', |
||
| 73 | 'level' => 2, |
||
| 74 | ), |
||
| 75 | array( |
||
| 76 | 'id' => '2', |
||
| 77 | 'parent' => null, |
||
| 78 | 'level' => 1, |
||
| 79 | ), |
||
| 80 | array( |
||
| 81 | 'id' => '2.1', |
||
| 82 | 'parent' => '2', |
||
| 83 | 'level' => 2, |
||
| 84 | ), |
||
| 85 | ); |
||
| 86 | $result = Utilities::flatToNested($flatTree); |
||
| 87 | |||
| 88 | $this->assertEquals( |
||
| 89 | array( |
||
| 90 | array( |
||
| 91 | 'id' => '1', |
||
| 92 | 'parent' => null, |
||
| 93 | 'level' => 1, |
||
| 94 | '_children' => array( |
||
| 95 | array( |
||
| 96 | 'id' => '1.2', |
||
| 97 | 'parent' => '1', |
||
| 98 | 'level' => 2, |
||
| 99 | '_children' => array(), |
||
| 100 | ), |
||
| 101 | ), |
||
| 102 | ), |
||
| 103 | array( |
||
| 104 | 'id' => '2', |
||
| 105 | 'parent' => null, |
||
| 106 | 'level' => 1, |
||
| 107 | '_children' => array( |
||
| 108 | array( |
||
| 109 | 'id' => '2.1', |
||
| 110 | 'parent' => '2', |
||
| 111 | 'level' => 2, |
||
| 112 | '_children' => array(), |
||
| 113 | ), |
||
| 114 | ), |
||
| 115 | ), |
||
| 116 | ), |
||
| 117 | $result |
||
| 118 | ); |
||
| 319 |