Conditions | 8 |
Paths | 18 |
Total Lines | 34 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Tests | 20 |
CRAP Score | 8 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
23 | 1 | public function indexAction() : array |
|
24 | { |
||
25 | 1 | $search = $this->di->get("request")->getGet("search"); |
|
26 | 1 | $latlon = ""; |
|
27 | |||
28 | 1 | if (filter_var($search, FILTER_VALIDATE_IP)) { |
|
29 | 1 | $res = $this->di->get("ipverifier")->getJson($search); |
|
30 | 1 | $latlon = ((!$res["latitude"]) || (!$res["longitude"])) ? "" : $res["latitude"] . "," . $res["longitude"]; |
|
31 | 1 | } else if ($search) { |
|
32 | 1 | $geocoder = $this->di->get("geocoder"); |
|
33 | 1 | $coords = new Coordinates($geocoder); |
|
34 | 1 | $latlon = $coords->getCoordinates($search); |
|
35 | } |
||
36 | 1 | if (($search) && ($latlon != "")) { |
|
37 | 1 | $darksky = $this->di->get("darksky"); |
|
38 | 1 | $type = $this->di->get("request")->getGet("type"); |
|
39 | 1 | if ($type == "past") { |
|
40 | 1 | $res = $darksky->getWeatherPast($latlon); |
|
41 | } else { |
||
42 | 1 | $res = $darksky->getWeatherComing($latlon); |
|
43 | } |
||
44 | |||
45 | $data = [ |
||
46 | 1 | "latlon" => $latlon, |
|
47 | 1 | "res" => $res |
|
48 | ]; |
||
49 | } else { |
||
50 | $data = [ |
||
51 | 1 | "code" => 400, |
|
52 | "error" => "You didnt search for anything" |
||
53 | ]; |
||
54 | } |
||
55 | |||
56 | 1 | return [$data]; |
|
57 | } |
||
59 |