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