| Conditions | 12 |
| Paths | 4 |
| Total Lines | 38 |
| Code Lines | 25 |
| 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 |
||
| 79 | private function executeQuery(string $url): AddressCollection |
||
| 80 | { |
||
| 81 | $content = $this->getUrlContents($url); |
||
| 82 | $data = json_decode($content, true); |
||
| 83 | |||
| 84 | if (!$data) { |
||
| 85 | return new AddressCollection([]); |
||
| 86 | } |
||
| 87 | |||
| 88 | // Return empty collection if address was not found |
||
| 89 | if (null === $data['lat'] |
||
| 90 | && null === $data['lng'] |
||
| 91 | && '(Unknown City?)' === $data['city'] |
||
| 92 | && '(Unknown Country?)' === $data['country_name'] |
||
| 93 | && 'XX' === $data['country_code']) { |
||
| 94 | return new AddressCollection([]); |
||
| 95 | } |
||
| 96 | |||
| 97 | // Return empty collection if address was not found |
||
| 98 | if (null === $data['lat'] |
||
| 99 | && null === $data['lng'] |
||
| 100 | && '(Private Address)' === $data['city'] |
||
| 101 | && '(Private Address)' === $data['country_name'] |
||
| 102 | && 'XX' === $data['country_code']) { |
||
| 103 | return new AddressCollection([]); |
||
| 104 | } |
||
| 105 | |||
| 106 | return new AddressCollection([ |
||
| 107 | Address::createFromArray([ |
||
| 108 | 'providedBy' => $this->getName(), |
||
| 109 | 'latitude' => $data['lat'], |
||
| 110 | 'longitude' => $data['lng'], |
||
| 111 | 'locality' => $data['city'], |
||
| 112 | 'country' => $data['country_name'], |
||
| 113 | 'countryCode' => $data['country_code'], |
||
| 114 | ]), |
||
| 115 | ]); |
||
| 116 | } |
||
| 117 | } |
||
| 118 |