WeatherController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 41
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 37 3
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