| Conditions | 11 |
| Paths | 512 |
| Total Lines | 36 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 26 |
| CRAP Score | 11.7975 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 15 | 22 | public static function createFromXml(SimpleXMLElement $xmlAddress) |
|
| 16 | { |
||
| 17 | 22 | $address = new DTO\Address(); |
|
| 18 | |||
| 19 | 22 | if (isset($xmlAddress->Ctry)) { |
|
| 20 | 22 | $address = $address->setCountry((string) $xmlAddress->Ctry); |
|
| 21 | 22 | } |
|
| 22 | 22 | if (isset($xmlAddress->CtrySubDvsn)) { |
|
| 23 | $address = $address->setCountrySubDivision((string) $xmlAddress->CtrySubDvsn); |
||
| 24 | } |
||
| 25 | 22 | if (isset($xmlAddress->Dept)) { |
|
| 26 | $address = $address->setDepartment((string) $xmlAddress->Dept); |
||
| 27 | } |
||
| 28 | 22 | if (isset($xmlAddress->SubDept)) { |
|
| 29 | $address = $address->setSubDepartment((string) $xmlAddress->SubDept); |
||
| 30 | } |
||
| 31 | 22 | if (isset($xmlAddress->StrtNm)) { |
|
| 32 | 21 | $address = $address->setStreetName((string) $xmlAddress->StrtNm); |
|
| 33 | 21 | } |
|
| 34 | 22 | if (isset($xmlAddress->BldgNb)) { |
|
| 35 | 6 | $address = $address->setBuildingNumber((string) $xmlAddress->BldgNb); |
|
| 36 | 6 | } |
|
| 37 | 22 | if (isset($xmlAddress->PstCd)) { |
|
| 38 | 6 | $address = $address->setPostCode((string) $xmlAddress->PstCd); |
|
| 39 | 6 | } |
|
| 40 | 22 | if (isset($xmlAddress->TwnNm)) { |
|
| 41 | 6 | $address = $address->setTownName((string) $xmlAddress->TwnNm); |
|
| 42 | 6 | } |
|
| 43 | 22 | if (isset($xmlAddress->AdrLine)) { |
|
| 44 | 16 | foreach ($xmlAddress->AdrLine as $line) { |
|
| 45 | 16 | $address = $address->addAddressLine((string)$line); |
|
| 46 | 16 | } |
|
| 47 | 16 | } |
|
| 48 | |||
| 49 | 22 | return $address; |
|
| 50 | } |
||
| 51 | } |
||
| 52 |