Conditions | 7 |
Paths | 64 |
Total Lines | 53 |
Code Lines | 27 |
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 |
||
157 | public function getCoordinates( |
||
158 | ?string $street = null, |
||
159 | ?string $streetNumber = null, |
||
160 | ?string $city = null, |
||
161 | ?string $zip = null, |
||
162 | ?string $country = null |
||
163 | ): Coordinates { |
||
164 | // init item |
||
165 | $item = array(); |
||
166 | |||
167 | // add street |
||
168 | if (!empty($street)) { |
||
169 | $item[] = $street; |
||
170 | } |
||
171 | |||
172 | // add street number |
||
173 | if (!empty($streetNumber)) { |
||
174 | $item[] = $streetNumber; |
||
175 | } |
||
176 | |||
177 | // add city |
||
178 | if (!empty($city)) { |
||
179 | $item[] = $city; |
||
180 | } |
||
181 | |||
182 | // add zip |
||
183 | if (!empty($zip)) { |
||
184 | $item[] = $zip; |
||
185 | } |
||
186 | |||
187 | // add country |
||
188 | if (!empty($country)) { |
||
189 | $item[] = $country; |
||
190 | } |
||
191 | |||
192 | // define value |
||
193 | $address = implode(' ', $item); |
||
194 | |||
195 | // define result |
||
196 | $results = $this->doCall(array( |
||
197 | 'address' => $address, |
||
198 | 'sensor' => 'false' |
||
199 | )); |
||
200 | |||
201 | if (!array_key_exists(0, $results)) { |
||
202 | throw Exception::noCoordinatesFoundforAddress([$street, $streetNumber, $city, $zip, $country]); |
||
203 | } |
||
204 | |||
205 | return new Coordinates( |
||
206 | $results[0]->geometry->location->lat, |
||
207 | $results[0]->geometry->location->lng |
||
208 | ); |
||
209 | } |
||
210 | } |
||
211 |