Conditions | 3 |
Paths | 3 |
Total Lines | 37 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 29 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
15 | 2 | public function indexAction() : object |
|
16 | { |
||
17 | 2 | $page = $this->di->get("page"); |
|
18 | 2 | $keys = $this->di->get("keys"); |
|
19 | 2 | $adress = $this->di->get("request")->getGet("location"); |
|
20 | 2 | $boolean = 0; |
|
21 | 2 | $res = ""; |
|
22 | 2 | $weatherResult = ""; |
|
23 | 2 | $result = ""; |
|
24 | |||
25 | 2 | if ($adress != "") { |
|
26 | 2 | if (filter_var($adress, FILTER_VALIDATE_IP)) { |
|
27 | 1 | $res = "$adress är en giltig IP adress"; |
|
28 | 1 | $boolean = 1; |
|
29 | 1 | $ipmodel = new IpModel(); |
|
30 | 1 | $tempip = $ipmodel->getIpData($adress); |
|
31 | 1 | $result = json_decode($tempip); |
|
32 | 1 | $weather = new WeatherModel(); |
|
33 | 1 | $weatherResult = $weather->getWeather($result->{'latitude'}, $result->{'longitude'}, $keys->getApiKey("darksky")); |
|
34 | } else { |
||
35 | 1 | $res = "$adress är inte en giltig IP adress"; |
|
36 | 1 | $boolean = 0; |
|
37 | } |
||
38 | } |
||
39 | |||
40 | 2 | $page->add("anax/controllerWeather/index", [ |
|
41 | 2 | "res" => $res, |
|
42 | 2 | "weatherForecast" => $weatherResult, |
|
43 | 2 | "location" => $result, |
|
44 | 2 | "bool" => $boolean |
|
45 | ]); |
||
46 | |||
47 | 2 | return $page->render([ |
|
48 | 2 | "res" => $res, |
|
49 | 2 | "weatherForecast" => $weatherResult, |
|
50 | 2 | "location" => $result, |
|
51 | 2 | "bool" => $boolean |
|
52 | ]); |
||
55 |