DIController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 72
c 1
b 0
f 0
dl 0
loc 103
ccs 71
cts 71
cp 1
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexActionGet() 0 39 1
B indexActionPost() 0 50 6
1
<?php
2
3
namespace Seb\DIController;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
/**
9
 *
10
 */
11
class DIController implements ContainerInjectableInterface
12
{
13
    use ContainerInjectableTrait;
14
15
    /**
16
     *
17
     * @return object
18
     */
19 1
    public function indexActionGet() : object
20
    {
21 1
        $title = "DI";
22 1
        $page = $this->di->get("page");
23 1
        $session = $this->di->get("session");
24
25 1
        $lon = $session->get("lon") ?? null;
26 1
        $lat = $session->get("lat") ?? null;
27 1
        $city = $session->get("city") ?? null;
28 1
        $country = $session->get("country") ?? null;
29 1
        $error = $session->get("error") ?? null;
30 1
        $history = $session->get("history") ?? null;
31 1
        $forecast = $session->get("forecast") ?? null;
32 1
        $map = $session->get("map") ?? null;
33
34
        $data = [
35 1
            "history" => $history,
36 1
            "forecast" => $forecast,
37 1
            "error" => $error,
38 1
            "lat" => $lat,
39 1
            "lon" => $lon,
40 1
            "city" => $city,
41 1
            "country" => $country,
42 1
            "map" => $map
43
        ];
44
45 1
        $session->set("lon", null);
46 1
        $session->set("lat", null);
47 1
        $session->set("city", null);
48 1
        $session->set("country", null);
49 1
        $session->set("error", null);
50 1
        $session->set("history", null);
51 1
        $session->set("forecast", null);
52 1
        $session->set("map", null);
53
54 1
        $page->add("DI/main", $data);
55
56 1
        return $page->render([
57 1
            "title" => $title,
58
        ]);
59
    }
60
61
    /**
62
     * @return object
63
     */
64 1
    public function indexActionPost() : object
65
    {
66 1
        $request = $this->di->get("request");
67 1
        $response = $this->di->get("response");
68 1
        $session = $this->di->get("session");
69
70 1
        $diCheck = $this->di->get("weather"); // <------------- egen DI-klass
71
72 1
        $lon = null;
73 1
        $lat = null;
74 1
        $city = null;
75 1
        $country = null;
76
77 1
        $ipCheck = $request->getPost("ipCheck") ?? null;
78 1
        $coCheck = $request->getPost("coCheck") ?? null;
79
80 1
        if ($ipCheck) {
81 1
            $ipPost = $request->getPost("ipPost");
82 1
            $arr = $diCheck->checkCords($ipPost);
83 1
            $lon = $arr[0];
84 1
            $lat = $arr[1];
85 1
            $city = $arr[2];
86 1
            $country = $arr[3];
87 1
        } elseif ($coCheck) {
88 1
            $lon = $request->getPost("lonPost");
89 1
            $lat = $request->getPost("latPost");
90
        }
91
92 1
        $coVali = $diCheck->validateCords($lat, $lon);
93
94 1
        if ($coVali) {
95 1
            $session->set("lon", $lon);
96 1
            $session->set("lat", $lat);
97 1
            $session->set("city", $city);
98 1
            $session->set("country", $country);
99 1
            $urlsHis = $diCheck->getHistWeatherUrls($lat, $lon);
100 1
            $resHistory = $diCheck->curlMulti($urlsHis);
101 1
            $urlsFore = $diCheck->getForecastWeatherUrl($lat, $lon);
102 1
            $resFore = $diCheck->curlMulti($urlsFore);
103 1
            $map = $diCheck->map($lat, $lon);
104 1
            $session->set("history", $resHistory);
105 1
            $session->set("forecast", $resFore);
106 1
            $session->set("map", $map);
107 1
        } elseif ($ipCheck) {
108 1
            $session->set("error", "IP är fel, kunde inte hitta position");
109 1
        } elseif ($coCheck) {
110 1
            $session->set("error", "Koordinater är fel, kunde inte hitta position");
111
        }
112
113 1
        return $response->redirect("di");
114
    }
115
}