IpApiController::indexActionGet()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 13
nc 2
nop 0
dl 0
loc 23
c 0
b 0
f 0
cc 2
ccs 13
cts 13
cp 1
crap 2
rs 9.8333
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