| Conditions | 1 |
| Paths | 1 |
| Total Lines | 90 |
| Code Lines | 85 |
| 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 |
||
| 227 | public function testXml2arrayWithCVCrossRef() { |
||
| 228 | $curriculumVitae = <<<XML |
||
| 229 | <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> |
||
| 230 | <root> |
||
| 231 | <langs> |
||
| 232 | <lang id="en">English</lang><lang id="fr">Français</lang> |
||
| 233 | </langs> |
||
| 234 | <curriculumVitae> |
||
| 235 | <lookingFor> |
||
| 236 | <experience crossref="curriculumVitae/experiences/items/experience[@id='SecondJob']/*"></experience> |
||
| 237 | <presentation lang="en">A good presentation.</presentation> |
||
| 238 | <presentation lang="fr">Une bonne présentation.</presentation> |
||
| 239 | </lookingFor> |
||
| 240 | <experiences anchor="experiences"> |
||
| 241 | <anchorTitle lang="en">Experiences</anchorTitle> |
||
| 242 | <anchorTitle lang="fr">Expériences Professionnelles</anchorTitle> |
||
| 243 | <items> |
||
| 244 | <experience id="SecondJob"> |
||
| 245 | <date lang="en">Apr 2011 - Present</date> |
||
| 246 | <date lang="fr">Avr. 2011 - Aujourd'hui</date> |
||
| 247 | <job lang="en">Second Job</job> |
||
| 248 | <job lang="fr">Deuxième Job</job> |
||
| 249 | <onesociety crossref="societies/society[@ref='ASociety']/*"></onesociety> |
||
| 250 | <missions lang="en"> |
||
| 251 | <item>A mission of my second job.</item> |
||
| 252 | </missions> |
||
| 253 | <missions lang="fr"> |
||
| 254 | <item>Une mission de mon deuxième job.</item> |
||
| 255 | </missions> |
||
| 256 | </experience> |
||
| 257 | <experience id="FirstJob"> |
||
| 258 | <date lang="en">Nov 2009 - Apr 2011</date> |
||
| 259 | <date lang="fr">Nov. 2009 - Avr. 2011</date> |
||
| 260 | <job lang="en">First Job</job> |
||
| 261 | <job lang="fr">Premier Job</job> |
||
| 262 | <onesociety crossref="societies/society[@ref='ASociety']/*"></onesociety> |
||
| 263 | <missions lang="en"> |
||
| 264 | <item>A mission of my first job.</item> |
||
| 265 | </missions> |
||
| 266 | <missions lang="fr"> |
||
| 267 | <item>Une mission de mon premier job.</item> |
||
| 268 | </missions> |
||
| 269 | </experience> |
||
| 270 | </items> |
||
| 271 | </experiences> |
||
| 272 | </curriculumVitae> |
||
| 273 | <societies> |
||
| 274 | <society ref="ASociety"> |
||
| 275 | <name>ASociety</name> |
||
| 276 | <myaddress>myaddress</myaddress> |
||
| 277 | <siteurl>http://cv.crassat.com</siteurl> |
||
| 278 | </society> |
||
| 279 | </societies> |
||
| 280 | </root> |
||
| 281 | XML; |
||
| 282 | |||
| 283 | $society = [ |
||
| 284 | 'name' => 'ASociety', |
||
| 285 | 'myaddress' => 'myaddress', |
||
| 286 | 'siteurl' => 'http://cv.crassat.com']; |
||
| 287 | $currentExperience = [ |
||
| 288 | 'job' => 'Second Job', |
||
| 289 | 'date' => 'Apr 2011 - Present', |
||
| 290 | 'onesociety' => $society, |
||
| 291 | 'missions' => [ |
||
| 292 | 'item' => ['A mission of my second job.']]]; |
||
| 293 | |||
| 294 | $expected = [ |
||
| 295 | 'langs' => [ |
||
| 296 | 'en' => 'English', |
||
| 297 | 'fr' => 'Français'], |
||
| 298 | 'curriculumVitae' => [ |
||
| 299 | 'lookingFor' => [ |
||
| 300 | 'experience' => $currentExperience, |
||
| 301 | 'presentation' => 'A good presentation.'], |
||
| 302 | 'experiences' => [ |
||
| 303 | 'anchorTitle' => 'Experiences', |
||
| 304 | 'items' => [ |
||
| 305 | 'SecondJob' => $currentExperience, |
||
| 306 | 'FirstJob' => [ |
||
| 307 | 'job' => 'First Job', |
||
| 308 | 'date' => 'Nov 2009 - Apr 2011', |
||
| 309 | 'onesociety' => $society, |
||
| 310 | 'missions' => [ |
||
| 311 | 'item' => ['A mission of my first job.']]]], |
||
| 312 | 'anchor' => 'experiences']], |
||
| 313 | 'societies' => ['society' => $society] |
||
| 314 | ]; |
||
| 315 | |||
| 316 | $this->assertXml2Array($expected, $curriculumVitae, $curriculumVitae); |
||
| 317 | } |
||
| 331 |