IpRestfulController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 17
dl 0
loc 36
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A indexActionPost() 0 23 4
1
<?php
2
3
namespace KW\KWcontroller;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
class IpRestfulController implements ContainerInjectableInterface
9
{
10
    use ContainerInjectableTrait;
11
12
    /**
13
     * This is the index method action, it handles:
14
     * POST METHOD mountpoint
15
     * POST METHOD mountpoint/
16
     * POST METHOD mountpoint/index
17
     * Return status of given ip-number
18
     *
19
     * @return array
20
     */
21 2
    public function indexActionPost() : array
22
    {
23
        //$ipn = $this->di->request->getPost("ipnummer");
24 2
        $ipn = $this->di->get("request")->getPost("ipnummer");
25 2
        if (!filter_var($ipn, FILTER_VALIDATE_IP)) {
26
            $json = [
27 1
                    "ip-number" => $ipn,
28 1
                    "message" => "Not a valid ip-number"
29
                ];
30
        } else {
31 1
            $type = (filter_var($ipn, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? "ipv4" : "ipv6" );
32 1
            $domainname = gethostbyaddr($ipn);
33
34 1
            $domainname = ($domainname == $ipn ? "none" : $domainname);
35
36
            $json = [
37 1
                    "ip-number" => $ipn,
38 1
                    "message" => "Valid ip-number",
39 1
                    "type" => $type,
40 1
                    "domain name" => $domainname
41
                ];
42
        }
43 2
        return [$json];
44
    }
45
}
46