IpValidatorAPIController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 82.35%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 31
c 1
b 0
f 0
ccs 14
cts 17
cp 0.8235
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexActionPost() 0 20 1
A initialize() 0 3 1
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