Conditions | 3 |
Paths | 3 |
Total Lines | 20 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 3.072 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | 1 | public function getCoordinates(String $search) : array |
|
23 | { |
||
24 | 1 | $key = $this->config->config; |
|
25 | |||
26 | 1 | if (is_string($search)) { |
|
|
|||
27 | 1 | $details = json_decode(file_get_contents("https://api.opencagedata.com/geocode/v1/json?q=$search&key={$key}")); |
|
28 | 1 | $results = $details->results; |
|
29 | 1 | if (isset($results[0]->geometry)) { |
|
30 | 1 | $valid = "Valid"; |
|
31 | 1 | $lat = $results[0]->geometry->lat; |
|
32 | 1 | $long = $results[0]->geometry->lng; |
|
33 | } else { |
||
34 | $valid = "Not valid, showing Gold Coast instead"; |
||
35 | $lat = -28.016666; |
||
36 | $long = 153.399994; |
||
37 | } |
||
38 | return [ |
||
39 | 1 | "valid" => $valid, |
|
40 | 1 | "lat" => $lat, |
|
41 | 1 | "long" => $long |
|
42 | ]; |
||
46 |