| Conditions | 13 |
| Paths | 4096 |
| Total Lines | 57 |
| Code Lines | 29 |
| 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 |
||
| 34 | private function getCustomerPostData(Customer $customer): array |
||
| 35 | { |
||
| 36 | $data = [ |
||
| 37 | 'first_name' => $customer->getFirstName(), |
||
| 38 | 'last_name' => $customer->getLastName(), |
||
| 39 | 'email' => $customer->getEmail(), |
||
| 40 | ]; |
||
| 41 | |||
| 42 | if ($customer->getGender()) { |
||
| 43 | $data['gender'] = $customer->getGender(); |
||
| 44 | } |
||
| 45 | |||
| 46 | if ($customer->getMiddleName()) { |
||
| 47 | $data['middle_name'] = $customer->getMiddleName(); |
||
| 48 | } |
||
| 49 | |||
| 50 | if ($customer->getCompanyName()) { |
||
| 51 | $data['company_name'] = $customer->getCompanyName(); |
||
| 52 | } |
||
| 53 | |||
| 54 | if ($customer->getVatNumber()) { |
||
| 55 | $data['vat_number'] = $customer->getVatNumber(); |
||
| 56 | } |
||
| 57 | |||
| 58 | if ($customer->getPostalcode()) { |
||
| 59 | $data['postalcode'] = $customer->getPostalcode(); |
||
| 60 | } |
||
| 61 | |||
| 62 | if ($customer->getHouseNumber()) { |
||
| 63 | $data['house_number'] = $customer->getHouseNumber(); |
||
| 64 | } |
||
| 65 | |||
| 66 | if ($customer->getHouseNumberAdd()) { |
||
| 67 | $data['house_number_add'] = $customer->getHouseNumberAdd(); |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($customer->getStreet()) { |
||
| 71 | $data['street'] = $customer->getStreet(); |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($customer->getCity()) { |
||
| 75 | $data['city'] = $customer->getCity(); |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($customer->getCountryCode()) { |
||
| 79 | $data['country_iso2'] = $customer->getCountryCode(); |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($customer->getLanguage()) { |
||
| 83 | $data['language'] = $customer->getLanguage(); |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($customer->getTelephone()) { |
||
| 87 | $data['telephone '] = $customer->getTelephone(); |
||
| 88 | } |
||
| 89 | |||
| 90 | return $data; |
||
| 91 | } |
||
| 174 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: