IpToJSONController   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 24
c 1
b 0
f 1
ccs 0
cts 8
cp 0
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateIpApiAction() 0 16 1
1
<?php
2
3
namespace Anax\Controller;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Anax\Models\IpValidator;
8
use Anax\Models\GeoApi;
9
10
/**
11
 * Controllerclass for the JSON-return of IP validation
12
 */
13
class IpToJSONController implements ContainerInjectableInterface
14
{
15
    use ContainerInjectableTrait;
16
17
    /**
18
     * validation of ip address and finding location based on ip
19
     * using the api model classes IpValidator and GeoApi
20
     */
21
    public function validateIpApiAction()
22
    {
23
        $ipAdress = $_GET["ipAdress"];
24
25
        // create instance of class GeoApi which inherits from IpValidator
26
        $ipAndLocation = $this->di->get("geoapi");
27
28
        $data = [
29
            "valid" => $ipAndLocation->validateIp($ipAdress)["res"],
30
            "domain" => $ipAndLocation->validateIp($ipAdress)["domain"] ?? null,
31
            "location" => $ipAndLocation->findGeoLocation($ipAdress) ?? null
32
        ];
33
34
        // rendering the result as formatted json
35
        json_encode($data, true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type integer expected by parameter $options of json_encode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        json_encode($data, /** @scrutinizer ignore-type */ true);
Loading history...
36
        return [[ $data ]];
37
    }
38
}
39