VaderController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 41
c 1
b 0
f 0
dl 0
loc 159
ccs 40
cts 40
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resultPageActionGet() 0 95 2
A indexActionPost() 0 29 2
A indexActionGet() 0 23 1
1
<?php
2
namespace Malm18\Vader;
3
4
use Anax\Commons\ContainerInjectableInterface;
5
use Anax\Commons\ContainerInjectableTrait;
6
7
// use Anax\Route\Exception\ForbiddenException;
8
// use Anax\Route\Exception\NotFoundException;
9
// use Anax\Route\Exception\InternalErrorException;
10
/**
11
 * A sample controller to show how a controller class can be implemented.
12
 * The controller will be injected with $di if implementing the interface
13
 * ContainerInjectableInterface, like this sample class does.
14
 * The controller is mounted on a particular route and can then handle all
15
 * requests for that mount point.
16
 *
17
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
18
 */
19
class VaderController implements ContainerInjectableInterface
20
{
21
    use ContainerInjectableTrait;
22
23 1
    public function indexActionGet() : object
24
    {
25
        // $vader = $this->di->get("vader");
26
        // $session = $this->di->session;
27
28
        // $ownIP = $vader->checkOwnIP();
29
30
31
32
33
34
        $data = [
35
            // "ownIP" => $ownIP
36 1
        ];
37
        // $parenting = $this->di->vader;
38
        // $parenting = $vader->parenting();
39
        // echo $parenting;
40
        // Add content as a view and then render the page
41 1
        $page = $this->di->get("page");
42
43 1
        $page->add("vader/vader", $data);
44
45 1
        return $page->render();
46
    }
47
48
49
50 4
    public function indexActionPost() : object
51
    {
52 4
        $session = $this->di->get("session");
53
        // $vader = $this->di->get("vader");
54
        // $ipHandler = new IpHandler();
55 4
        $request = $this->di->get("request");
56 4
        $response = $this->di->get("response");
57 4
        $theIP = $request->getPost("ip1");
58 4
        $pastOrFuture = $request->getPost("pastOrFuture");
59
60 4
        if (!is_null($theIP)) {
61
            // $ipInfo = $ipHandler->checkIP($theIP);
62
            // $ipInfo2 = json_decode($ipInfo, true);
63
            // $ipInfo3 = gettype($ipInfo);
64
            // echo $ipInfo3;
65
            // var_dump(json_decode($ipInfo, true));
66
            // var_dump($ipInfo2);
67
            // var_dump($ipInfo['ip']);
68 4
            $session->set("ip1", $theIP);
69 4
            $session->set("pastOrFuture", $pastOrFuture);
70
            // $session->set("hostname", $ipInfo['hostname']);
71
            // $session->set("type", $ipInfo['type']);
72
            // $session->set("latitude", $ipInfo['latitude']);
73
            // $session->set("longitude", $ipInfo['longitude']);
74
            // $session->set("city", $ipInfo['city']);
75
            // $session->set("country_name", $ipInfo['country_name']);
76
            // var_dump($session);
77
        }
78 4
            return $response->redirect("vader/resultpage");
79
    }
80
81
82
83 4
    public function resultPageActionGet() : object
84
    {
85
86
87 4
        $session = $this->di->get("session");
88
89 4
        $theIP = $session->get("ip1");
90
91 4
        $pastOrFuture = $session->get("pastOrFuture");
92
93 4
        $vader = $this->di->get("vader");
94
95 4
        $ipHandler = new \Malm18\IPChecker\IPHandler();
96
97 4
        $coordinates = $vader->checkCoordinates($theIP);
98
99 4
        if ($coordinates) {
100 3
            $latitude = $coordinates['latitude'];
101 3
            $longitude = $coordinates['longitude'];
102
103 3
            $weather = $vader->checkWeather($latitude, $longitude, $pastOrFuture);
104
105
            // print_r($weather);
106
107 3
            $minLat = $ipHandler->minLat($latitude);
108 3
            $maxLat = $ipHandler->maxLat($latitude);
109 3
            $minLong = $ipHandler->minLong($longitude);
110 3
            $maxLong = $ipHandler->maxLong($longitude);
111
112 3
            $mapLink = $ipHandler->mapLink($latitude, $longitude, $minLat, $maxLat, $minLong, $maxLong);
113
114
            // $var = 5;
115
            // $var_is_greater_than_two = ($var > 2 ? true : false);
116
117
            // var_dump($coordinates);
118
119
120
    // framåt
121
    // bakåt
122
    //         Array ( [daily] => Array ( [data] => Array ( [0] => Array ( [daily] => Array ( [data] => Array ( [0] => Array ( [time] => 1574636400
123
    //         Array ( [daily] => Array ( [data] => Array ( [0] => Array ( [time] => 1574636400
124
125
            // print_r($weather);
126
127 3
            $weather2 = $vader->checkWeather2($weather);
128
129
            // print_r($weather2);
130
131
            // var_dump($weather2);
132
            // $session->set("ip1", "ip2");
133
134
            // $hostname = $session->get("hostname");
135
            // $city = $session->get("city");
136
            // $country_name = $session->get("country_name");
137
            // $latitude = $session->get("latitude");
138
            // $longitude = $session->get("longitude");
139
            // $type = $session->get("type");
140
141
            // var_dump($session);
142
143
144
145
            // $data = [
146
            //     "ip1" => $theIP,
147
            //     "city" => $ipInfo['city'],
148
            //     "country_name" => $ipInfo['country_name'],
149
            //     "latitude" => $ipInfo['latitude'],
150
            //     "longitude" => $ipInfo['longitude'],
151
            //     "mapLink" => $mapLink,
152
            //     "continent_name" => $ipInfo['continent_name'],
153
            //     "region_name" => $ipInfo['region_name'],
154
            //     "type" => $ipInfo['type']
155
            // ];
156
157
            $data = [
158 3
                "weather2" => $weather2,
159 3
                "theIP" => $theIP,
160 3
                "mapLink" => $mapLink
161
            ]
162
                ;
163
164
            // Add content as a view and then render the page
165 3
            $page = $this->di->get("page");
166
            // $data = [
167
            //     "content" => "HELLO!"
168
            // ];
169 3
            $page->add("vader/resultPage", $data);
170
        } else {
171 1
            $page = $this->di->get("page");
172 1
            $page->add("vader/noResultPage");
173
        }
174
        // $page->add("anax/v2/article/default", $data, "sidebar-left");
175
        // $page->add("anax/v2/article/default", $data, "sidebar-right");
176
        // $page->add("anax/v2/article/default", $data, "flash");
177 4
        return $page->render();
178
    }
179
}
180