WeatherController::indexAction()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 37
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 29
nc 3
nop 0
dl 0
loc 37
ccs 29
cts 29
cp 1
crap 3
rs 9.456
c 0
b 0
f 0
1
<?php
2
3
namespace Anax\Controller;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
/**
9
 * A controller for flat file markdown content.
10
 */
11
class WeatherController implements ContainerInjectableInterface
12
{
13
    use ContainerInjectableTrait;
14
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
        ]);
53
    }
54
}
55