weather_after   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 50
dl 0
loc 103
c 1
b 0
f 0
ccs 47
cts 47
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 67 2
A ipJson() 0 9 1
A result() 0 6 2
1
<?php
2
3
namespace Moody\weather_and_position;
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
14
/**
15
 * A sample controller to show how a controller class can be implemented.
16
 * The controller will be injected with $di if implementing the interface
17
 * ContainerInjectableInterface, like this sample class does.
18
 * The controller is mounted on a particular route and can then handle all
19
 * requests for that mount point.
20
 *
21
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
22
 */
23
class weather_after implements ContainerInjectableInterface
24
{
25
26
27
28
29
30
    use ContainerInjectableTrait;
31
32
    protected $ipAddress;
33
    protected $object;
34
35
36
37 2
    public function result($ipAddress, $object) : string
38
    {
39 2
        if ($object->getProtocol($ipAddress)) {
40 1
            return "The IP $ipAddress is a valid " . $object->getProtocol($ipAddress) ." address." ;
41
        }
42 1
        return "The IP $ipAddress is not a valid ip-Address.";
43
    }
44
45 1
    public function indexAction() : object
46
    {
47
48
        // Deal with the action and return a response.
49 1
        $protocol =  null;
0 ignored issues
show
Unused Code introduced by
The assignment to $protocol is dead and can be removed.
Loading history...
50 1
        $host = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $host is dead and can be removed.
Loading history...
51
52 1
        $title = "Ip validator";
53 1
        $page = $this->di->get("page");
54 1
        $request = $this->di->get("request");
55 1
        $this->ipAddress = $request->getGet("ip");
56
57 1
        $ip = $this->ipAddress;
0 ignored issues
show
Unused Code introduced by
The assignment to $ip is dead and can be removed.
Loading history...
58
59 1
        $this->object = $this->di->get("IpValidate");
60 1
        $this->openWeatherMapModel = $this->di->get("openWeatherMap");
0 ignored issues
show
Bug Best Practice introduced by
The property openWeatherMapModel does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
61 1
        $this->object->getDetails();
62
        
63 1
        foreach ($this->openWeatherMapModel as $key => $value) :
64 1
            $this->object->setMessage($value);
65
        endforeach;
66
67
68 1
        $protocol = $this->result($this->ipAddress, $this->object);
69 1
        $host = $this->object->getDomain($this->ipAddress);
70 1
        $address = $this->object->getAddress($this->ipAddress);
71 1
        $latitude =  $address["latitude"] ??null;
72 1
        $longitude = $address["longitude"] ??null;
73
        
74
        
75 1
        $weatherSet = $this->object->setWeather($latitude, $longitude);
76
        // $weatherSet2 = $this->object->setWeather2($latitude, $longitude);
77
        
78 1
        $weatherGet = $this->object->getWeather();
79
        // $weatherGet2 = $this->object->getWeather2();
80 1
        $getData = $this->object->getData($weatherGet);
81
        // $getDataArray = $this->object->getDataArray($weatherGet2);
82
83
84
85
86
87 1
        $ip = $this->object->getCurrentIp($this->ipAddress);
88 1
        $Domain = $this->object->getDomain($this->ipAddress);
89
90 1
        $json = $this->ipJson($this->ipAddress, $this->object);
91 1
        $data['json'] = $json;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
92 1
        $data["ip"] = $ip;
93 1
        $data["protocol"] = $protocol;
94 1
        $data["host"] = $host;
95 1
        $data["address"] = $address;
96 1
        $data["Domain"] = $Domain;
97 1
        $data["latitude"] = $latitude;
98 1
        $data["longitude"] = $longitude;
99 1
        $data["weatherSet"] = $weatherSet;
100
        // $data["weatherSet2"] = $weatherSet2;
101 1
        $data["getData"] = $getData;
102
        // $data["getDataArray"] = $getDataArray;
103
104
105
        // var_dump($getData);
106
107
108
109 1
        $page->add("weather/after", $data);
110 1
        return $page->render([
111 1
            "title" => $title,
112
        ]);
113
    }
114
115
116
117 1
    public function ipJson($ipAddress, $object) : array
118
    {
119
        $json = [
120 1
            "ip" => $ipAddress,
121 1
            "Protocol" => $object->getProtocol($ipAddress) ?? null,
122 1
            "Domain" => $object->getDomain($ipAddress) ?? null,
123 1
            "address" => $object->getData($this->object->getWeather()) ?? null
124
        ];
125 1
        return [$json];
126
    }
127
}
128