WeatherController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 56
dl 0
loc 85
ccs 56
cts 56
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A indexActionGet() 0 21 1
A weatherActionGet() 0 22 1
A weatherOldActionGet() 0 33 3
1
<?php
2
3
namespace Anax\Controller;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Chai17\Models;
8
9
class WeatherController implements ContainerInjectableInterface
10
{
11
    use ContainerInjectableTrait;
12
13 1
    public function indexActionGet() : object
14
    {
15 1
        $title = "Weather";
16 1
        $page = $this->di->get("page");
17 1
        $session = $this->di->get("session");
18 1
        $api = $this->di->get("ipstack");
19 1
        $ipstack = $api["config"];
20 1
        $getipInfo = new Models\Curl;
21 1
        $extra =  "&fields=ip";
22 1
        $userIp =  $getipInfo->cUrl($ipstack["url"]. "check". '?access_key='. $ipstack["key"]. $extra);
23 1
        $apiResult = json_decode($userIp, true);
24
25 1
        $session->set("userIp", $apiResult["ip"]);
26
27 1
        $page->add("weather/index", [
28 1
            "ip" => $session->get("userIp"),
29
            "res" => null,
30
        ]);
31
32 1
        return $page->render([
33 1
            "title" => $title,
34
        ]);
35
    }
36
37 1
    public function weatherActionGet()
38
    {
39 1
        $title = "Weather";
40 1
        $ipstack = $this->di->get("ipstack");
41 1
        $mapquest = $this->di->get("mapquest");
42 1
        $darksky = $this->di->get("darksky");
43 1
        $getJson = new Models\Curl;
44 1
        $map = new Models\Map;
45 1
        $locationHandler = new Models\Location;
46
47 1
        $request = $this->di->get("request");
48 1
        $page = $this->di->get("page");
49 1
        $ipNumber = $request->getGet("ip");
50 1
        $location = $locationHandler->getLocation($ipNumber, $ipstack["config"], $mapquest["config"]);
51
52 1
        $mapDiv = $map->getMap($location["latitude"], $location["longitude"]);
53 1
        $weatherJson = $getJson->cUrl($darksky["config"]["url"]. $darksky["config"]["key"]. "/". $location["latitude"]. ",". $location["longitude"]. "?lang=sv&units=auto");
54
55 1
        $weather = json_decode($weatherJson, true);
56 1
        $page->add("weather/weather", ["location" => $location, "mapDiv" => $mapDiv, "weather" => $weather]);
57
58 1
        return $page->render(["title" => $title,]);
59
    }
60
61 1
    public function weatherOldActionGet()
62
    {
63 1
        $title = "Weather Old";
64 1
        $ipstack = $this->di->get("ipstack");
65 1
        $mapquest = $this->di->get("mapquest");
66 1
        $darksky = $this->di->get("darksky");
67
68 1
        $getJson = new Models\Curl;
69 1
        $map = new Models\Map;
70 1
        $locationHandler = new Models\Location;
71
72 1
        $request = $this->di->get("request");
73 1
        $page = $this->di->get("page");
74 1
        $ipNumber = $request->getGet("ip");
75 1
        $location = $locationHandler->getLocation($ipNumber, $ipstack["config"], $mapquest["config"]);
76
77 1
        $url = [];
78 1
        for ($i=0; $i < 31; $i++) {
79 1
            $time  = time() - ($i * 24 * 60 * 60);
80 1
            array_push($url, $darksky["config"]["url"]. $darksky["config"]["key"]. "/". $location["latitude"]. ",". $location["longitude"]. ",". $time. "?lang=sv&units=auto");
81
        }
82
83 1
        $mapDiv = $map->getMap($location["latitude"], $location["longitude"]);
84 1
        $weatherJson = $getJson->cUrlMulti($url);
85 1
        $weather = [];
86 1
        $count = count($weatherJson);
87 1
        for ($i=0; $i < $count; $i++) {
88 1
            array_push($weather, json_decode($weatherJson[$i], true));
89
        }
90
91 1
        $page->add("weather/weatherOld", ["location" => $location, "mapDiv" => $mapDiv, "weather" => $weather]);
92
93 1
        return $page->render(["title" => $title,]);
94
    }
95
}
96