IpVerifyJsonController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 57
ccs 18
cts 18
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A indexActionGet() 0 21 2
1
<?php
2
3
namespace Anax\Controller;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Anax\IpVerify\IpVerify;
8
9
// use Anax\Route\Exception\ForbiddenException;
10
// use Anax\Route\Exception\NotFoundException;
11
// use Anax\Route\Exception\InternalErrorException;
12
13
/**
14
 * A sample JSON controller to show how a controller class can be implemented.
15
 * The controller will be injected with $di if implementing the interface
16
 * ContainerInjectableInterface, like this sample class does.
17
 * The controller is mounted on a particular route and can then handle all
18
 * requests for that mount point.
19
 */
20
class IpVerifyJsonController implements ContainerInjectableInterface
21
{
22
    use ContainerInjectableTrait;
23
    protected $ipVerify;
24
    protected $request;
25
26
27
    /**
28
     * @var string $db a sample member variable that gets initialised
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 2
    public function initialize() : void
40
    {
41
        // Use to initialise member variables.
42 2
        $this->ipVerify = new IpVerify();
43 2
        $this->request = $this->di->get("request");
44 2
    }
45
46
47
48
    /**
49
     * This is the index method action, it handles:
50
     * GET METHOD mountpoint
51
     * GET METHOD mountpoint/
52
     * GET METHOD mountpoint/index
53
     *
54
     * @return array
55
     */
56 2
    public function indexActionGet() : array
57
    {
58 2
        $ipAddress = $this->request->getGet("ip");
59 2
        if ($ipAddress) {
60 1
            $protocol = $this->ipVerify->getIpInfo($ipAddress);
61 1
            $isValid = $this->ipVerify->ipVerify($ipAddress);
62 1
            $domain = $this->ipVerify->getDomain($ipAddress);
63
        } else {
64 1
            $protocol = "";
65 1
            $domain = "";
66 1
            $isValid = false;
67
        }
68
69
        
70
        $json = [
71 2
            "protocol" => $protocol,
72 2
            "domain" => $domain,
73 2
            "ip" => $ipAddress,
74 2
            "isValid" => $isValid,
75
        ];
76 2
        return [$json];
77
    }
78
}
79