| Conditions | 10 |
| Paths | 144 |
| Total Lines | 62 |
| Code Lines | 40 |
| 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 |
||
| 130 | private function xmlResultToArray(\DOMElement $resultNode, \DOMElement $addressNode, string $attribution, bool $reverse): Location |
||
| 131 | { |
||
| 132 | $builder = new AddressBuilder($this->getName()); |
||
| 133 | |||
| 134 | foreach (['state', 'county'] as $i => $tagName) { |
||
| 135 | if (null !== ($adminLevel = $this->getNodeValue($addressNode->getElementsByTagName($tagName)))) { |
||
| 136 | $builder->addAdminLevel($i + 1, $adminLevel, ''); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | // get the first postal-code when there are many |
||
| 141 | $postalCode = $this->getNodeValue($addressNode->getElementsByTagName('postcode')); |
||
| 142 | if (!empty($postalCode)) { |
||
| 143 | $postalCode = current(explode(';', $postalCode)); |
||
| 144 | } |
||
| 145 | $builder->setPostalCode($postalCode); |
||
| 146 | |||
| 147 | $localityFields = ['city', 'town', 'village', 'hamlet']; |
||
| 148 | foreach ($localityFields as $localityField) { |
||
| 149 | $localityFieldContent = $this->getNodeValue($addressNode->getElementsByTagName($localityField)); |
||
| 150 | if (!empty($localityFieldContent)) { |
||
| 151 | $builder->setLocality($localityFieldContent); |
||
| 152 | |||
| 153 | break; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | $builder->setStreetName($this->getNodeValue($addressNode->getElementsByTagName('road')) ?: $this->getNodeValue($addressNode->getElementsByTagName('pedestrian'))); |
||
| 158 | $builder->setStreetNumber($this->getNodeValue($addressNode->getElementsByTagName('house_number'))); |
||
| 159 | $builder->setSubLocality($this->getNodeValue($addressNode->getElementsByTagName('suburb'))); |
||
| 160 | $builder->setCountry($this->getNodeValue($addressNode->getElementsByTagName('country'))); |
||
| 161 | |||
| 162 | $countryCode = $this->getNodeValue($addressNode->getElementsByTagName('country_code')); |
||
| 163 | if (!empty($countryCode)) { |
||
| 164 | $countryCode = strtoupper($countryCode); |
||
| 165 | } |
||
| 166 | $builder->setCountryCode($countryCode); |
||
| 167 | |||
| 168 | $builder->setCoordinates($resultNode->getAttribute('lat'), $resultNode->getAttribute('lon')); |
||
| 169 | |||
| 170 | $boundsAttr = $resultNode->getAttribute('boundingbox'); |
||
| 171 | if ($boundsAttr) { |
||
| 172 | $bounds = []; |
||
| 173 | list($bounds['south'], $bounds['north'], $bounds['west'], $bounds['east']) = explode(',', $boundsAttr); |
||
| 174 | $builder->setBounds($bounds['south'], $bounds['west'], $bounds['north'], $bounds['east']); |
||
| 175 | } |
||
| 176 | |||
| 177 | $location = $builder->build(NominatimAddress::class); |
||
| 178 | $location = $location->withAttribution($attribution); |
||
| 179 | $location = $location->withOSMId(intval($resultNode->getAttribute('osm_id'))); |
||
| 180 | $location = $location->withOSMType($resultNode->getAttribute('osm_type')); |
||
| 181 | |||
| 182 | if (false === $reverse) { |
||
| 183 | $location = $location->withClass($resultNode->getAttribute('class')); |
||
| 184 | $location = $location->withDisplayName($resultNode->getAttribute('display_name')); |
||
| 185 | $location = $location->withType($resultNode->getAttribute('type')); |
||
| 186 | } else { |
||
| 187 | $location = $location->withDisplayName($resultNode->nodeValue); |
||
| 188 | } |
||
| 189 | |||
| 190 | return $location; |
||
| 191 | } |
||
| 192 | |||
| 231 |
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.