JsonIpController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 119
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A geoJsonActionPost() 0 8 2
A jsonActionPost() 0 6 1
A testJsonActionGet() 0 7 1
A geojsonActionGet() 0 8 2
A jsonActionGet() 0 6 1
A initialize() 0 4 1
1
<?php
2
3
namespace Anax\Controller;
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
 * A sample JSON controller to show how a controller class can be implemented.
14
 * The controller will be injected with $di if implementing the interface
15
 * ContainerInjectableInterface, like this sample class does.
16
 * The controller is mounted on a particular route and can then handle all
17
 * requests for that mount point.
18
 */
19
class JsonIpController implements ContainerInjectableInterface
20
{
21
    use ContainerInjectableTrait;
22
23
24
25
    /**
26
     * @var string $db a sample member variable that gets initialised
27
     */
28
    private $db = "not active";
29
30
31
32
    /**
33
     * The initialize method is optional and will always be called before the
34
     * target method/action. This is a convienient method where you could
35
     * setup internal properties that are commonly used by several methods.
36
     *
37
     * @return void
38
     */
39 14
    public function initialize() : void
40
    {
41
        // Use to initialise member variables.
42 14
        $this->db = "active";
43 14
    }
44
45
46
47
    /**
48
     * This is the index method action, it handles:
49
     * GET METHOD mountpoint
50
     * GET METHOD mountpoint/
51
     * GET METHOD mountpoint/index
52
     *
53
     * @return array
54
     */
55 2
    public function testJsonActionGet() : array
56
    {
57
        // Deal with the action and return a response.
58
        $json = [
59 2
            "message" => __METHOD__ . ", \$db is {$this->db}",
60
        ];
61 2
        return [$json];
62
    }
63
64
65
66
    /**
67
     * This is the index method action, it handles:
68
     * GET METHOD mountpoint
69
     * GET METHOD mountpoint/
70
     * GET METHOD mountpoint/index
71
     *
72
     * @return array
73
     */
74 3
    public function jsonActionGet() : array
75
    {
76 3
        $request = $this->di->get("request");
77 3
        $ipm = $this->di->get("callurlmodel");
78 3
        $ipm->setIpAddress($request->getGet("ip"));
79 3
        return [$ipm->validateIp()];
80
    }
81
82
83
84
    /**
85
     * This is the index method action, it handles:
86
     * GET METHOD mountpoint
87
     * GET METHOD mountpoint/
88
     * GET METHOD mountpoint/index
89
     *
90
     * @return array
91
     */
92 3
    public function jsonActionPost() : array
93
    {
94 3
        $request = $this->di->get("request");
95 3
        $ipm = $this->di->get("callurlmodel");
96 3
        $ipm->setIpAddress($request->getPost("ip"));
97 3
        return [$ipm->validateIp()];
98
    }
99
100
101
102
    /**
103
     * This is the index method action, it handles:
104
     * GET METHOD mountpoint
105
     * GET METHOD mountpoint/
106
     * GET METHOD mountpoint/index
107
     *
108
     * @return array
109
     */
110 3
    public function geojsonActionGet() : array
111
    {
112 3
        $request = $this->di->get("request");
113 3
        $client = $request->getServer('REMOTE_ADDR');
114 3
        $ipaddress = $request->getGet("ip") ? $request->getGet("ip") : $client;
115 3
        $ipm = $this->di->get("callurlmodel");
116 3
        $ipm->setIpAddress($ipaddress);
117 3
        return [$ipm->fetchGeoInfo()];
118
    }
119
120
121
122
    /**
123
     * This is the index method action, it handles:
124
     * GET METHOD mountpoint
125
     * GET METHOD mountpoint/
126
     * GET METHOD mountpoint/index
127
     *
128
     * @return array
129
     */
130 3
    public function geoJsonActionPost() : array
131
    {
132 3
        $request = $this->di->get("request");
133 3
        $client = $request->getServer('REMOTE_ADDR');
134 3
        $ipaddress = $request->getPost("ip") ? $request->getPost("ip") : $client;
135 3
        $ipm = $this->di->get("callurlmodel");
136 3
        $ipm->setIpAddress($ipaddress);
137 3
        return [$ipm->fetchGeoInfo()];
138
    }
139
}
140