| Conditions | 19 |
| Paths | 16 |
| Total Lines | 71 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 105 | private function executeQuery(string $url, string $locale = null, int $limit): AddressCollection |
||
| 106 | { |
||
| 107 | if (null !== $locale) { |
||
| 108 | $url = sprintf('%s&lang=%s', $url, str_replace('_', '-', $locale)); |
||
| 109 | } |
||
| 110 | |||
| 111 | $url = sprintf('%s&results=%d', $url, $limit); |
||
| 112 | $content = $this->getUrlContents($url); |
||
| 113 | $json = json_decode($content, true); |
||
| 114 | |||
| 115 | if (empty($json) || isset($json['error']) || |
||
| 116 | (isset($json['response']) && '0' === $json['response']['GeoObjectCollection']['metaDataProperty']['GeocoderResponseMetaData']['found']) |
||
| 117 | ) { |
||
| 118 | return new AddressCollection([]); |
||
| 119 | } |
||
| 120 | |||
| 121 | $data = $json['response']['GeoObjectCollection']['featureMember']; |
||
| 122 | |||
| 123 | $locations = []; |
||
| 124 | foreach ($data as $item) { |
||
| 125 | $builder = new AddressBuilder($this->getName()); |
||
| 126 | $bounds = null; |
||
| 127 | $flatArray = ['pos' => ' ']; |
||
| 128 | |||
| 129 | array_walk_recursive( |
||
| 130 | $item['GeoObject'], |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @param string $value |
||
| 134 | */ |
||
| 135 | function ($value, $key) use (&$flatArray) { |
||
| 136 | $flatArray[$key] = $value; |
||
| 137 | } |
||
| 138 | ); |
||
| 139 | |||
| 140 | if (!empty($flatArray['lowerCorner']) && !empty($flatArray['upperCorner'])) { |
||
| 141 | $lowerCorner = explode(' ', $flatArray['lowerCorner']); |
||
| 142 | $upperCorner = explode(' ', $flatArray['upperCorner']); |
||
| 143 | $builder->setBounds( |
||
| 144 | (float) $lowerCorner[1], |
||
| 145 | (float) $lowerCorner[0], |
||
| 146 | (float) $upperCorner[1], |
||
| 147 | (float) $upperCorner[0] |
||
| 148 | ); |
||
| 149 | } |
||
| 150 | |||
| 151 | $coordinates = explode(' ', $flatArray['pos']); |
||
| 152 | $builder->setCoordinates((float) $coordinates[1], (float) $coordinates[0]); |
||
| 153 | |||
| 154 | foreach (['AdministrativeAreaName', 'SubAdministrativeAreaName'] as $i => $name) { |
||
| 155 | if (isset($flatArray[$name])) { |
||
| 156 | $builder->addAdminLevel($i + 1, $flatArray[$name], null); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | $builder->setStreetNumber(isset($flatArray['PremiseNumber']) ? $flatArray['PremiseNumber'] : null); |
||
| 161 | $builder->setStreetName(isset($flatArray['ThoroughfareName']) ? $flatArray['ThoroughfareName'] : null); |
||
| 162 | $builder->setSubLocality(isset($flatArray['DependentLocalityName']) ? $flatArray['DependentLocalityName'] : null); |
||
| 163 | $builder->setLocality(isset($flatArray['LocalityName']) ? $flatArray['LocalityName'] : null); |
||
| 164 | $builder->setCountry(isset($flatArray['CountryName']) ? $flatArray['CountryName'] : null); |
||
| 165 | $builder->setCountryCode(isset($flatArray['CountryNameCode']) ? $flatArray['CountryNameCode'] : null); |
||
| 166 | |||
| 167 | /** @var YandexAddress $location */ |
||
| 168 | $location = $builder->build(YandexAddress::class); |
||
| 169 | $location = $location->withPrecision(isset($flatArray['precision']) ? $flatArray['precision'] : null); |
||
| 170 | $location = $location->withName(isset($flatArray['name']) ? $flatArray['name'] : null); |
||
| 171 | $locations[] = $location; |
||
| 172 | } |
||
| 173 | |||
| 174 | return new AddressCollection($locations); |
||
| 175 | } |
||
| 176 | } |
||
| 177 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.