| Conditions | 11 |
| Paths | 17 |
| Total Lines | 54 |
| Code Lines | 37 |
| 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 |
||
| 105 | private function executeQuery(string $url, int $limit): Collection |
||
| 106 | { |
||
| 107 | $content = $this->getUrlContents($url); |
||
| 108 | $json = json_decode($content, true); |
||
| 109 | |||
| 110 | if (isset($json['type'])) { |
||
| 111 | switch ($json['type']['subtype']) { |
||
| 112 | case 'InvalidInputData': |
||
| 113 | throw new InvalidArgument('Input parameter validation failed.'); |
||
| 114 | case 'QuotaExceeded': |
||
| 115 | throw new QuotaExceeded('Valid request but quota exceeded.'); |
||
| 116 | case 'InvalidCredentials': |
||
| 117 | throw new InvalidCredentials('Invalid or missing api key.'); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | if (!isset($json['Response']) || empty($json['Response'])) { |
||
| 122 | return new AddressCollection([]); |
||
| 123 | } |
||
| 124 | |||
| 125 | if (!isset($json['Response']['View'][0])) { |
||
| 126 | return new AddressCollection([]); |
||
| 127 | } |
||
| 128 | |||
| 129 | $locations = $json['Response']['View'][0]['Result']; |
||
| 130 | |||
| 131 | foreach ($locations as $loc) { |
||
| 132 | $location = $loc['Location']; |
||
| 133 | $builder = new AddressBuilder($this->getName()); |
||
| 134 | $coordinates = isset($location['NavigationPosition'][0]) ? $location['NavigationPosition'][0] : $location['DisplayPosition']; |
||
| 135 | $builder->setCoordinates($coordinates['Latitude'], $coordinates['Longitude']); |
||
| 136 | $bounds = $location['MapView']; |
||
| 137 | |||
| 138 | $builder->setBounds($bounds['BottomRight']['Latitude'], $bounds['TopLeft']['Longitude'], $bounds['TopLeft']['Latitude'], $bounds['BottomRight']['Longitude']); |
||
| 139 | $builder->setStreetNumber($location['Address']['HouseNumber'] ?? null); |
||
| 140 | $builder->setStreetName($location['Address']['Street'] ?? null); |
||
| 141 | $builder->setPostalCode($location['Address']['PostalCode'] ?? null); |
||
| 142 | $builder->setLocality($location['Address']['City'] ?? null); |
||
| 143 | $builder->setSubLocality($location['Address']['District'] ?? null); |
||
| 144 | $builder->setCountry($location['Address']['AdditionalData'][0]['value'] ?? null); |
||
| 145 | $builder->setCountryCode($location['Address']['Country'] ?? null); |
||
| 146 | |||
| 147 | $address = $builder->build(HereAddress::class); |
||
| 148 | $address = $address->withLocationId($location['LocationId']); |
||
| 149 | $address = $address->withLocationType($location['LocationType']); |
||
| 150 | $results[] = $address; |
||
| 151 | |||
| 152 | if (count($results) >= $limit) { |
||
| 153 | break; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | return new AddressCollection($results); |
||
| 158 | } |
||
| 159 | |||
| 168 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.