| Conditions | 11 | 
| Paths | 88 | 
| Total Lines | 65 | 
| Code Lines | 44 | 
| 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  | 
            ||
| 87 | private function searchGazetteer($query): collection  | 
            ||
| 88 |     { | 
            ||
| 89 |         $key          = Site::getPreference('openroute_key'); | 
            ||
| 90 | $data = new Collection();  | 
            ||
| 91 | $user_service = new UserService();  | 
            ||
| 92 | |||
| 93 |         if ($key === '') { | 
            ||
| 94 | $url = self::NOMINATIM_URL;  | 
            ||
| 95 | $qry = [  | 
            ||
| 96 | 'q' => rawurlencode($query),  | 
            ||
| 97 | 'format' => 'jsonv2',  | 
            ||
| 98 | 'limit' => static::LIMIT,  | 
            ||
| 99 | 'accept-language' => I18N::languageTag(),  | 
            ||
| 100 | 'featuretype' => 'settlement',  | 
            ||
| 101 | 'email' => rawurlencode($user_service->administrators()->first()->email()),  | 
            ||
| 102 | ];  | 
            ||
| 103 |         } else { | 
            ||
| 104 | $url = self::OPENROUTE_URL;  | 
            ||
| 105 | $qry = [  | 
            ||
| 106 | 'api_key' => $key,  | 
            ||
| 107 | 'text' => rawurlencode($query),  | 
            ||
| 108 | 'layers' => 'coarse',  | 
            ||
| 109 | 'size' => static::LIMIT,  | 
            ||
| 110 | ];  | 
            ||
| 111 | }  | 
            ||
| 112 | |||
| 113 | // Read from the URL  | 
            ||
| 114 | $client = new Client();  | 
            ||
| 115 |         try { | 
            ||
| 116 | $json = $client->get($url, array_merge(self::GUZZLE_OPTIONS, ['query' => $qry]))->getBody()->__toString();  | 
            ||
| 117 | $results = json_decode($json, false);  | 
            ||
| 118 |             if (json_last_error() !== JSON_ERROR_NONE) { | 
            ||
| 119 |                 throw new Exception(I18N::translate('Geocoder: %s', json_last_error_msg())); | 
            ||
| 120 | }  | 
            ||
| 121 |             if ($key === '') { | 
            ||
| 122 |                 foreach ($results as $result) { | 
            ||
| 123 | $data->add($result->display_name);  | 
            ||
| 124 | }  | 
            ||
| 125 |             } else { | 
            ||
| 126 |                 $place_elements = array_filter(explode(',', Site::getPreference('openroute_parts'))); | 
            ||
| 127 |                 foreach ($results->features as $result) { | 
            ||
| 128 |                     if (empty($place_elements)) { | 
            ||
| 129 | $place = $result->properties->label;  | 
            ||
| 130 |                     } else { | 
            ||
| 131 | $place_parts = [];  | 
            ||
| 132 |                         foreach ($place_elements as $place_element) { | 
            ||
| 133 |                             if (isset($result->properties->{$place_element})) { | 
            ||
| 134 |                                 array_push($place_parts, $result->properties->{$place_element}); | 
            ||
| 135 | }  | 
            ||
| 136 | }  | 
            ||
| 137 | $place = implode(Gedcom::PLACE_SEPARATOR, $place_parts);  | 
            ||
| 138 | }  | 
            ||
| 139 | // It's possible that with a strange selection of  | 
            ||
| 140 | // place elements the resulting place could end up empty  | 
            ||
| 141 |                     if ($place !== '') { | 
            ||
| 142 | $data->add($place);  | 
            ||
| 143 | }  | 
            ||
| 144 | }  | 
            ||
| 145 | }  | 
            ||
| 146 |         } catch (Exception | RequestException $ex) { | 
            ||
| 147 | // Json error? Service down? Quota exceeded?  | 
            ||
| 148 | $data->add($ex->getMessage());  | 
            ||
| 149 | }  | 
            ||
| 150 | |||
| 151 | return $data;  | 
            ||
| 152 | }  | 
            ||
| 154 |