weather_befor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 49
dl 0
loc 106
c 1
b 0
f 0
ccs 46
cts 46
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ipJson() 0 9 1
A result() 0 6 2
A indexAction() 0 75 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_befor implements ContainerInjectableInterface
24
{
25
    use ContainerInjectableTrait;
26
27
    protected $ipAddress;
28
    protected $object;
29
30
31
32 2
    public function result($ipAddress, $object) : string
33
    {
34 2
        if ($object->getProtocol($ipAddress)) {
35 1
            return "The IP $ipAddress is a valid " . $object->getProtocol($ipAddress) ." address." ;
36
        }
37 1
        return "The IP $ipAddress is not a valid ip-Address.";
38
    }
39
40 1
    public function indexAction() : object
41
    {
42
        // Deal with the action and return a response.
43 1
        $protocol =  null;
0 ignored issues
show
Unused Code introduced by
The assignment to $protocol is dead and can be removed.
Loading history...
44 1
        $host = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $host is dead and can be removed.
Loading history...
45
        // $address = null;
46
        // $latitude = null;
47
        // $longitude = null;
48
49 1
        $title = "Ip validator";
50 1
        $page = $this->di->get("page");
51 1
        $request = $this->di->get("request");
52 1
        $this->ipAddress = $request->getGet("ip");
53 1
        $ip = $this->ipAddress;
0 ignored issues
show
Unused Code introduced by
The assignment to $ip is dead and can be removed.
Loading history...
54
55 1
        $this->object = $this->di->get("IpValidate");
56
57
58 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...
59
60
61 1
        foreach ($this->openWeatherMapModel as $key => $value) :
62 1
            $this->object->setMessage($value);
63
        endforeach;
64
65
66
67 1
        $protocol = $this->result($this->ipAddress, $this->object);
68 1
        $host = $this->object->getDomain($this->ipAddress);
69 1
        $address = $this->object->getAddress($this->ipAddress);
70 1
        $latitude =  $address["latitude"] ??null;
71 1
        $longitude = $address["longitude"] ??null;
72
        // var_dump($latitude);
73
        // var_dump($longitude);
74
        
75
        
76
        // $weatherSet = $this->object->setWeather($latitude, $longitude);
77 1
        $weatherSet2 = $this->object->setWeather2($latitude, $longitude);
78
        
79
        // $weatherGet = $this->object->getWeather();
80 1
        $weatherGet2 = $this->object->getWeather2();
81
        
82
83
        // $getData = $this->object->getData($weatherGet);
84 1
        $getDataArray = $this->object->getDataArray($weatherGet2);
85
86
87
88
89
90 1
        $ip = $this->object->getCurrentIp($this->ipAddress);
91 1
        $Domain = $this->object->getDomain($this->ipAddress);
92
93 1
        $json = $this->ipJson($this->ipAddress, $this->object);
94 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...
95 1
        $data["ip"] = $ip;
96 1
        $data["protocol"] = $protocol;
97 1
        $data["host"] = $host;
98 1
        $data["address"] = $address;
99 1
        $data["Domain"] = $Domain;
100 1
        $data["latitude"] = $latitude;
101 1
        $data["longitude"] = $longitude;
102
        // $data["weatherSet"] = $weatherSet;
103 1
        $data["weatherSet2"] = $weatherSet2;
104
        // $data["getData"] = $getData;
105 1
        $data["getDataArray"] = $getDataArray;
106
107
108
        // var_dump($getDataArray);
109
110
111
112 1
        $page->add("weather/befor", $data);
113 1
        return $page->render([
114 1
            "title" => $title,
115
        ]);
116
    }
117
118
119
120 1
    public function ipJson($ipAddress, $object) : array
121
    {
122
        $json = [
123 1
            "ip" => $ipAddress,
124 1
            "Protocol" => $object->getProtocol($ipAddress) ?? null,
125 1
            "Domain" => $object->getDomain($ipAddress) ?? null,
126 1
            "address" => $object->getDataArray($this->object->getWeather2()) ?? null
127
        ];
128 1
        return [$json];
129
    }
130
}
131