| Conditions | 1 |
| Paths | 1 |
| Total Lines | 148 |
| Code Lines | 113 |
| 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 |
||
| 121 | public function testFlatToNestedComplexTree() |
||
| 122 | { |
||
| 123 | $flatTree = array( |
||
| 124 | array( |
||
| 125 | 'id' => '1', |
||
| 126 | 'parent' => null, |
||
| 127 | 'level' => 1, |
||
| 128 | ), |
||
| 129 | array( |
||
| 130 | 'id' => '1.2', |
||
| 131 | 'parent' => '1', |
||
| 132 | 'level' => 2, |
||
| 133 | ), |
||
| 134 | array( |
||
| 135 | 'id' => '1.2.1', |
||
| 136 | 'parent' => '1.2', |
||
| 137 | 'level' => 3, |
||
| 138 | ), |
||
| 139 | array( |
||
| 140 | 'id' => '1.2.1.1', |
||
| 141 | 'parent' => '1.2.1', |
||
| 142 | 'level' => 4, |
||
| 143 | ), |
||
| 144 | array( |
||
| 145 | 'id' => '2.1', |
||
| 146 | 'parent' => '1', |
||
| 147 | 'level' => 2, |
||
| 148 | ), |
||
| 149 | array( |
||
| 150 | 'id' => '2.1.1', |
||
| 151 | 'parent' => '2.1', |
||
| 152 | 'level' => 3, |
||
| 153 | ), |
||
| 154 | array( |
||
| 155 | 'id' => '2.1.2', |
||
| 156 | 'parent' => '2.1', |
||
| 157 | 'level' => 3, |
||
| 158 | ), |
||
| 159 | array( |
||
| 160 | 'id' => '2.1.3', |
||
| 161 | 'parent' => '2.1', |
||
| 162 | 'level' => 3, |
||
| 163 | ), |
||
| 164 | array( |
||
| 165 | 'id' => '2', |
||
| 166 | 'parent' => null, |
||
| 167 | 'level' => 1, |
||
| 168 | ), |
||
| 169 | array( |
||
| 170 | 'id' => '2.1', |
||
| 171 | 'parent' => '2', |
||
| 172 | 'level' => 2, |
||
| 173 | ), |
||
| 174 | array( |
||
| 175 | 'id' => '2.1.1', |
||
| 176 | 'parent' => '2.1', |
||
| 177 | 'level' => 3, |
||
| 178 | ), |
||
| 179 | array( |
||
| 180 | 'id' => '2.2', |
||
| 181 | 'parent' => '2', |
||
| 182 | 'level' => 2, |
||
| 183 | ), |
||
| 184 | ); |
||
| 185 | $result = Utilities::flatToNested($flatTree); |
||
| 186 | |||
| 187 | $this->assertEquals( |
||
| 188 | array( |
||
| 189 | array( |
||
| 190 | 'id' => '1', |
||
| 191 | 'parent' => null, |
||
| 192 | 'level' => 1, |
||
| 193 | '_children' => array( |
||
| 194 | array( |
||
| 195 | 'id' => '1.2', |
||
| 196 | 'parent' => '1', |
||
| 197 | 'level' => 2, |
||
| 198 | '_children' => array( |
||
| 199 | array( |
||
| 200 | 'id' => '1.2.1', |
||
| 201 | 'parent' => '1.2', |
||
| 202 | 'level' => 3, |
||
| 203 | '_children' => array( |
||
| 204 | array( |
||
| 205 | 'id' => '1.2.1.1', |
||
| 206 | 'parent' => '1.2.1', |
||
| 207 | 'level' => 4, |
||
| 208 | '_children' => array(), |
||
| 209 | ), |
||
| 210 | ), |
||
| 211 | ), |
||
| 212 | ), |
||
| 213 | ), |
||
| 214 | array( |
||
| 215 | 'id' => '2.1', |
||
| 216 | 'parent' => '1', |
||
| 217 | 'level' => 2, |
||
| 218 | '_children' => array( |
||
| 219 | array( |
||
| 220 | 'id' => '2.1.1', |
||
| 221 | 'parent' => '2.1', |
||
| 222 | 'level' => 3, |
||
| 223 | '_children' => array(), |
||
| 224 | ), |
||
| 225 | array( |
||
| 226 | 'id' => '2.1.2', |
||
| 227 | 'parent' => '2.1', |
||
| 228 | 'level' => 3, |
||
| 229 | '_children' => array(), |
||
| 230 | ), |
||
| 231 | array( |
||
| 232 | 'id' => '2.1.3', |
||
| 233 | 'parent' => '2.1', |
||
| 234 | 'level' => 3, |
||
| 235 | '_children' => array(), |
||
| 236 | ), |
||
| 237 | ), |
||
| 238 | ), |
||
| 239 | ), |
||
| 240 | ), |
||
| 241 | array( |
||
| 242 | 'id' => '2', |
||
| 243 | 'parent' => null, |
||
| 244 | 'level' => 1, |
||
| 245 | '_children' => array( |
||
| 246 | array( |
||
| 247 | 'id' => '2.1', |
||
| 248 | 'parent' => '2', |
||
| 249 | 'level' => 2, |
||
| 250 | '_children' => array( |
||
| 251 | array( |
||
| 252 | 'id' => '2.1.1', |
||
| 253 | 'parent' => '2.1', |
||
| 254 | 'level' => 3, |
||
| 255 | '_children' => array(), |
||
| 256 | ), |
||
| 257 | ), |
||
| 258 | ), |
||
| 259 | array( |
||
| 260 | 'id' => '2.2', |
||
| 261 | 'parent' => '2', |
||
| 262 | 'level' => 2, |
||
| 263 | '_children' => array(), |
||
| 264 | ), |
||
| 265 | ), |
||
| 266 | ), |
||
| 267 | ), |
||
| 268 | $result |
||
| 269 | ); |
||
| 319 |