AsaTirsen /
weather
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Asti\Api; |
||
| 4 | |||
| 5 | use Anax\Commons\ContainerInjectableInterface; |
||
| 6 | use Anax\Commons\ContainerInjectableTrait; |
||
| 7 | use Asti\Weather\WeatherService; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * A test controller to show off using a model. |
||
| 11 | */ |
||
| 12 | class WeatherApiController implements ContainerInjectableInterface |
||
| 13 | { |
||
| 14 | use ContainerInjectableTrait; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * function checks if input is an ip address and if so, if it's PIv4 or Ipv6 |
||
| 18 | */ |
||
| 19 | // public function indexAction() |
||
| 20 | // { |
||
| 21 | |||
| 22 | // } |
||
| 23 | |||
| 24 | 1 | public function weatherActionPost() : array |
|
| 25 | { |
||
| 26 | 1 | $request = $this->di->get("request"); |
|
| 27 | 1 | $geoipService = $this->di->get("location"); |
|
| 28 | 1 | $weatherService = $this->di->get("weather"); |
|
| 29 | 1 | $ipAdress = $request->getPost("ipCheck"); |
|
| 30 | 1 | $res = $geoipService->curlIpApi($ipAdress); |
|
| 31 | |||
| 32 | 1 | if (isset($res["Message"])) { |
|
| 33 | return [$res]; |
||
| 34 | } |
||
| 35 | 1 | if (in_array("Prognos", $request->getPost())) { |
|
| 36 | 1 | return [$weatherService->curlWeatherApi($res[0]["Longitude"], $res[0]["Latitude"])]; |
|
| 37 | 1 | } elseif ((in_array("Äldre data", $request->getPost()))) { |
|
| 38 | 1 | return [$weatherService->curlOldWeatherApi($res[0]["Longitude"], $res[0]["Latitude"])]; |
|
| 39 | } |
||
|
0 ignored issues
–
show
|
|||
| 40 | } |
||
| 41 | } |
||
| 42 |
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: