| 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 | ||
| 24 | private function getCustomerPatchData(Customer $customer): array | ||
| 25 |     { | ||
| 26 | $data = [ | ||
| 27 | 'first_name' => $customer->getFirstName(), | ||
| 28 | 'last_name' => $customer->getLastName(), | ||
| 29 | 'email' => $customer->getEmail(), | ||
| 30 | ]; | ||
| 31 | |||
| 32 |         if ($customer->getGender()) { | ||
| 33 | $data['gender'] = $customer->getGender(); | ||
| 34 | } | ||
| 35 | |||
| 36 |         if ($customer->getMiddleName()) { | ||
| 37 | $data['middle_name'] = $customer->getMiddleName(); | ||
| 38 | } | ||
| 39 | |||
| 40 |         if ($customer->getCompanyName()) { | ||
| 41 | $data['company_name'] = $customer->getCompanyName(); | ||
| 42 | } | ||
| 43 | |||
| 44 |         if ($customer->getVatNumber()) { | ||
| 45 | $data['vat_number'] = $customer->getVatNumber(); | ||
| 46 | } | ||
| 47 | |||
| 48 |         if ($customer->getPostalcode()) { | ||
| 49 | $data['postalcode'] = $customer->getPostalcode(); | ||
| 50 | } | ||
| 51 | |||
| 52 |         if ($customer->getHouseNumber()) { | ||
| 53 | $data['house_number'] = $customer->getHouseNumber(); | ||
| 54 | } | ||
| 55 | |||
| 56 |         if ($customer->getHouseNumberAdd()) { | ||
| 57 | $data['house_number_add'] = $customer->getHouseNumberAdd(); | ||
| 58 | } | ||
| 59 | |||
| 60 |         if ($customer->getStreet()) { | ||
| 61 | $data['street'] = $customer->getStreet(); | ||
| 62 | } | ||
| 63 | |||
| 64 |         if ($customer->getCity()) { | ||
| 65 | $data['city'] = $customer->getCity(); | ||
| 66 | } | ||
| 67 | |||
| 68 |         if ($customer->getCountryCode()) { | ||
| 69 | $data['country_iso2'] = $customer->getCountryCode(); | ||
| 70 | } | ||
| 71 | |||
| 72 |         if ($customer->getLanguage()) { | ||
| 73 | $data['language'] = $customer->getLanguage(); | ||
| 74 | } | ||
| 75 | |||
| 76 |         if ($customer->getTelephone()) { | ||
| 77 | $data['telephone '] = $customer->getTelephone(); | ||
| 78 | } | ||
| 79 | |||
| 80 | return $data; | ||
| 81 | } | ||
| 127 | 
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: