1 | <?php |
||
2 | namespace Anax\Model; |
||
3 | |||
4 | class Coordinates |
||
5 | { |
||
6 | private $config; |
||
7 | /** |
||
8 | * Constructor, allow for $di to be injected. |
||
9 | * |
||
10 | * @param Array $config for api key |
||
11 | */ |
||
12 | 1 | public function __construct($config) |
|
13 | { |
||
14 | 1 | $this->config = $config; |
|
15 | 1 | } |
|
16 | |||
17 | 1 | public function setConfig($config) |
|
18 | { |
||
19 | 1 | $this->config = $config; |
|
20 | 1 | } |
|
21 | |||
22 | 1 | public function getCoordinates(String $search) : array |
|
23 | { |
||
24 | 1 | $key = $this->config->config; |
|
25 | |||
26 | 1 | if (is_string($search)) { |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
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 | ]; |
||
43 | } |
||
0 ignored issues
–
show
The function implicitly returns
null when the if condition on line 26 is false . This is incompatible with the type-hinted return array . Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: interface ReturnsInt {
public function returnsIntHinted(): int;
}
class MyClass implements ReturnsInt {
public function returnsIntHinted(): int
{
if (foo()) {
return 123;
}
// here: null is implicitly returned
}
}
![]() |
|||
44 | } |
||
45 | } |
||
46 |