IpApiController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 35
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A indexActionGet() 0 23 2
1
<?php
2
3
namespace Blixter\IpValidate;
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 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
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
20
 */
21
class IpApiController implements ContainerInjectableInterface
22
{
23
    use ContainerInjectableTrait;
24
25
    /**
26
     * This is the index method action, it handles:
27
     * GET METHOD mountpoint
28
     * GET METHOD mountpoint/
29
     * GET METHOD mountpoint/index
30
     *
31
     * @return Array
32
     */
33 1
    public function indexActionGet(): array
34
    {
35 1
        $request = $this->di->get("request");
36 1
        $ipaddress = $request->getGet("ip");
37
        // Using ipValidation class from $di.
38 1
        $ipValidation = $this->di->get("ipvalidation");
39
40 1
        $isIpValid = $ipValidation->isIpValid($ipaddress);
41
42 1
        if ($isIpValid) {
43 1
            $protocol = $ipValidation->getProtocol($ipaddress);
44 1
            $domain = $ipValidation->getdomain($ipaddress);
45
        }
46
47
        $data = [
48 1
            "ipaddress" => $ipaddress,
49 1
            "isIpValid" => $isIpValid,
50 1
            "protocol" => $protocol ?? null,
51 1
            "domain" => $domain ?? null,
52
        ];
53
54
        // Deal with the action and return a response.
55 1
        return [$data];
56
    }
57
}
58