IpValidatorAPIController::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
nc 1
nop 0
dl 0
loc 3
c 1
b 0
f 0
cc 1
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Teca\IpValidator;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
class IpValidatorAPIController implements ContainerInjectableInterface
9
{
10
    use ContainerInjectableTrait;
11
12
    protected $validator = null;
13
14
    public function initialize()
15
    {
16
        $this->validator = $this->di->get("ipValidator");
17
    }
18
19 1
    public function indexActionPost() : array
20
    {
21 1
        $request = $this->di->get("request");
22 1
        $ipAddress = $request->getPost("ip");
23
24 1
        $geo = $this->validator->getGeo($ipAddress);
25
26
        $json = [
27 1
            "ip" => $ipAddress,
28 1
            "ipv4" => $this->validator->verifyIpv4($ipAddress),
29 1
            "ipv6" => $this->validator->verifyIpv6($ipAddress),
30 1
            "domain" => $this->validator->getDomain($ipAddress),
31 1
            "latitude" => $geo["latitude"],
32 1
            "longitude" => $geo["longitude"],
33 1
            "country_name" => $geo["country_name"],
34 1
            "region_name" => $geo["region_name"],
35 1
            "city" => $geo["city"]
36
        ];
37
38 1
        return [$json];
39
    }
40
}
41