Conditions | 56 |
Paths | > 20000 |
Total Lines | 110 |
Code Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | 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 |
||
369 | public static function createFromXML(SimpleXMLElement $xml) |
||
370 | { |
||
371 | if (!isset($xml->Record)) { |
||
372 | throw new BpostInvalidXmlResponseException('"Record" missing'); |
||
373 | } |
||
374 | |||
375 | $recordXml = $xml->Record; |
||
376 | |||
377 | $poi = new Poi(); |
||
378 | |||
379 | if (isset($recordXml->Id) && $recordXml->Id != '') { |
||
380 | $poi->setId((string) $recordXml->Id); |
||
381 | } |
||
382 | if (isset($recordXml->ID) && $recordXml->ID != '') { |
||
383 | $poi->setId((string) $recordXml->ID); |
||
384 | } |
||
385 | if (isset($recordXml->Type) && $recordXml->Type != '') { |
||
386 | $poi->setType((string) $recordXml->Type); |
||
387 | } |
||
388 | if (isset($recordXml->Name) && $recordXml->Name != '') { |
||
389 | $poi->setOffice((string) $recordXml->Name); |
||
390 | } |
||
391 | if (isset($recordXml->OFFICE) && $recordXml->OFFICE != '') { |
||
392 | $poi->setOffice((string) $recordXml->OFFICE); |
||
393 | } |
||
394 | if (isset($recordXml->Street) && $recordXml->Street != '') { |
||
395 | $poi->setStreet((string) $recordXml->Street); |
||
396 | } |
||
397 | if (isset($recordXml->STREET) && $recordXml->STREET != '') { |
||
398 | $poi->setStreet((string) $recordXml->STREET); |
||
399 | } |
||
400 | if (isset($recordXml->Number) && $recordXml->Number != '') { |
||
401 | $poi->setNr((string) $recordXml->Number); |
||
402 | } |
||
403 | if (isset($recordXml->NR) && $recordXml->NR != '') { |
||
404 | $poi->setNr((string) $recordXml->NR); |
||
405 | } |
||
406 | if (isset($recordXml->Zip) && $recordXml->Zip != '') { |
||
407 | $poi->setZip((string) $recordXml->Zip); |
||
408 | } |
||
409 | if (isset($recordXml->ZIP) && $recordXml->ZIP != '') { |
||
410 | $poi->setZip((string) $recordXml->ZIP); |
||
411 | } |
||
412 | if (isset($recordXml->City) && $recordXml->City != '') { |
||
413 | $poi->setCity((string) $recordXml->City); |
||
414 | } |
||
415 | if (isset($recordXml->CITY) && $recordXml->CITY != '') { |
||
416 | $poi->setCity((string) $recordXml->CITY); |
||
417 | } |
||
418 | if (isset($recordXml->X) && $recordXml->X != '') { |
||
419 | $poi->setX((int) $recordXml->X); |
||
420 | } |
||
421 | if (isset($recordXml->Y) && $recordXml->Y != '') { |
||
422 | $poi->setY((int) $recordXml->Y); |
||
423 | } |
||
424 | if (isset($recordXml->Longitude) && $recordXml->Longitude != '') { |
||
425 | $poi->setLongitude((float) $recordXml->Longitude); |
||
426 | } |
||
427 | if (isset($recordXml->Latitude) && $recordXml->Latitude != '') { |
||
428 | $poi->setLatitude((float) $recordXml->Latitude); |
||
429 | } |
||
430 | if (isset($recordXml->Services) && isset($recordXml->Services->Service)) { |
||
431 | foreach ($recordXml->Services->Service as $service) { |
||
432 | $poi->addService(Service::createFromXML($service)); |
||
433 | } |
||
434 | } |
||
435 | |||
436 | if (isset($recordXml->Hours)) { |
||
437 | $recordHoursXml = $recordXml->Hours; |
||
438 | |||
439 | if (isset($recordHoursXml->Monday)) { |
||
440 | $poi->addHour(Day::DAY_INDEX_MONDAY, Day::createFromXML($recordHoursXml->Monday)); |
||
441 | } |
||
442 | if (isset($recordHoursXml->Tuesday)) { |
||
443 | $poi->addHour(Day::DAY_INDEX_TUESDAY, Day::createFromXML($recordHoursXml->Tuesday)); |
||
444 | } |
||
445 | if (isset($recordHoursXml->Wednesday)) { |
||
446 | $poi->addHour(Day::DAY_INDEX_WEDNESDAY, Day::createFromXML($recordHoursXml->Wednesday)); |
||
447 | } |
||
448 | if (isset($recordHoursXml->Thursday)) { |
||
449 | $poi->addHour(Day::DAY_INDEX_THURSDAY, Day::createFromXML($recordHoursXml->Thursday)); |
||
450 | } |
||
451 | if (isset($recordHoursXml->Friday)) { |
||
452 | $poi->addHour(Day::DAY_INDEX_FRIDAY, Day::createFromXML($recordHoursXml->Friday)); |
||
453 | } |
||
454 | if (isset($recordHoursXml->Saturday)) { |
||
455 | $poi->addHour(Day::DAY_INDEX_SATURDAY, Day::createFromXML($recordHoursXml->Saturday)); |
||
456 | } |
||
457 | if (isset($recordHoursXml->Sunday)) { |
||
458 | $poi->addHour(Day::DAY_INDEX_SUNDAY, Day::createFromXML($recordHoursXml->Sunday)); |
||
459 | } |
||
460 | } |
||
461 | |||
462 | if (isset($recordXml->ClosedFrom) && $recordXml->ClosedFrom != '') { |
||
463 | $closedFrom = (string) $recordXml->ClosedFrom; |
||
464 | $poi->setClosedFrom((array) $closedFrom); |
||
465 | } |
||
466 | if (isset($recordXml->ClosedTo) && $recordXml->ClosedTo != '') { |
||
467 | $closedTo = (string) $recordXml->ClosedTo; |
||
468 | $poi->setClosedTo((array) $closedTo); |
||
469 | } |
||
470 | if (isset($recordXml->NOTE) && $recordXml->NOTE != '') { |
||
471 | $poi->setNote((string) $recordXml->NOTE); |
||
472 | } |
||
473 | |||
474 | if (isset($xml->Page) && isset($xml->Page['ServiceRef']) && $xml->Page['ServiceRef'] != '') { |
||
475 | $poi->setPage($xml->Page['ServiceRef']); |
||
476 | } |
||
477 | |||
478 | return $poi; |
||
479 | } |
||
481 |