WeatherController   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 48
c 2
b 0
f 0
dl 0
loc 80
ccs 48
cts 48
cp 1
rs 10
wmc 11

4 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 14 4
A initialize() 0 4 1
A previousActionGet() 0 25 3
A responseActionGet() 0 21 3
1
<?php
2
3
namespace Osln\Weather;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
// use Anax\Route\Exception\ForbiddenException;
9
use Anax\Route\Exception\NotFoundException;
10
// use Anax\Route\Exception\InternalErrorException;
11
12
/**
13
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
14
 */
15
class WeatherController implements ContainerInjectableInterface
16
{
17
    use ContainerInjectableTrait;
18 3
    public function initialize() : void
19
    {
20 3
        $this->config = new LoadConfig();
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21 3
        $this->ipvalidate = new Ipvalidate();
0 ignored issues
show
Bug Best Practice introduced by
The property ipvalidate does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22 3
    }
23
    /**
24
     * This is the index method action, it handles:
25
     * ANY METHOD mountpoint
26
     * ANY METHOD mountpoint/
27
     * ANY METHOD mountpoint/index
28
     *
29
     * @return string
30
     */
31 1
    public function indexAction() : object
32
    {
33 1
        $page = $this->di->get("page");
34 1
        $session = $this->di->get("session");
35
        $data = [
36 1
            "title" => "Väder",
37 1
            "forecast" => $session->has("forecast") ? $session->get("forecast") : "",
38 1
            "month" => $session->has("month") ? $session->get("month") : "",
39 1
            "error" => $session->has("error") ? $session->get("error") : "",
40 1
            "location" => "",
41
        ];
42 1
        $page->add("osln/weather/default", $data);
43 1
        $session->delete("error");
44 1
        return $page->render();
45
    }
46
47 1
    public function responseActionGet()
48
    {
49 1
        $search = $this->di->request->getGet("location");
0 ignored issues
show
Bug introduced by
Accessing request on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
50 1
        $session = $this->di->get("session");
51 1
        $session->delete("month");
52 1
        $url = $this->ipvalidate->getUrl($search);
53
54 1
        $data = $this->di->curl->fetch($url);
0 ignored issues
show
Bug introduced by
Accessing curl on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
55 1
        $forecast = null;
56
57 1
        if (isset($data["latitude"])) {
58 1
            $forecast = $this->di->weather->forecast($data["latitude"], $data["longitude"]);
0 ignored issues
show
Bug introduced by
Accessing weather on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
59 1
        } elseif (isset($data[0]["lat"])) {
60 1
            $forecast = $this->di->weather->forecast($data[0]["lat"], $data[0]["lon"]);
61
        } else {
62 1
            $session->set("error", "Could not find this location");
63
        }
64 1
        $session->set("forecast", $forecast);
65
66 1
        $resp = $this->di->get("response");
67 1
        return $resp->redirect("weather");
68
        // return [$data];
69
    }
70 1
    public function previousActionGet()
71
    {
72 1
        $search = $this->di->request->getGet("location");
0 ignored issues
show
Bug introduced by
Accessing request on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
73 1
        $session = $this->di->get("session");
74 1
        $url = $this->ipvalidate->getUrl($search);
75
76 1
        $data = $this->di->curl->fetch($url);
0 ignored issues
show
Bug introduced by
Accessing curl on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
77 1
        $forecast = null;
78 1
        $month = null;
79
        
80 1
        if (isset($data["latitude"])) {
81 1
            $forecast = $this->di->weather->forecast($data["latitude"], $data["longitude"]);
0 ignored issues
show
Bug introduced by
Accessing weather on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
82 1
            $month = $this->di->weather->getLastMonth($data["latitude"], $data["longitude"]);
83 1
        } elseif (isset($data[0]["lat"])) {
84 1
            $forecast = $this->di->weather->forecast($data[0]["lat"], $data[0]["lon"]);
85 1
            $month = $this->di->weather->getLastMonth($data[0]["lat"], $data[0]["lon"]);
86
        } else {
87 1
            $session->set("error", "Could not find this location");
88
        }
89
        // return [$forecast];
90 1
        $session->set("forecast", $forecast);
91 1
        $session->set("month", $month);
92
93 1
        $resp = $this->di->get("response");
94 1
        return $resp->redirect("weather");
95
    }
96
}
97