Issues (33)

src/MeModule/ValidateIPJsonController.php (1 issue)

1
<?php
2
3
namespace Anax\Controller;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Hab\MeModule;
8
9
// use Anax\Route\Exception\ForbiddenException;
10
// use Anax\Route\Exception\NotFoundException;
11
// use Anax\Route\Exception\InternalErrorException;
12
13
/**
14
 * A sample controller to show how a controller class can be implemented.
15
 * The controller will be injected with $di if implementing the interface
16
 * ContainerInjectableInterface, like this sample class does.
17
 * The controller is mounted on a particular route and can then handle all
18
 * requests for that mount point.
19
 *
20
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
21
 */
22
class ValidateIPJsonController implements ContainerInjectableInterface
23
{
24
    use ContainerInjectableTrait;
25
26
27
28
    /**
29
     * @var string $res is the response of filters on selected IP
30
     */
31
    private $res = [];
32
33
34
    /**
35
     * The initialize method is optional and will always be called before the
36
     * target method/action. This is a convienient method where you could
37
     * setup internal properties that are commonly used by several methods.
38
     *
39
     * @return void
40
     */
41 3
    public function initialize() : void
42
    {
43
        // Use to initialise member variables.
44 3
        $this->res = [];
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type string of property $res.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45 3
    }
46
47
48
49
    /**
50
     * Takes string from GET query.
51
     * Calculates if string is valid ipv4/ipv6 address
52
     * and if there is a host attached to it.
53
     * Returns response as JSON.
54
     * @return array
55
     */
56 3
    public function indexActionGet() : array
57
    {
58 3
        $request = $this->di->get("request");
59 3
        $ip = $request->getGet("ip", "");
60
        
61 3
        $validator = new \Hab\MeModule\ValidateIP($ip);
62 3
        $data = $validator->sendRes();
63 3
        $this->res["data"] = $data;
64
65 3
        return [$this->res];
66
    }
67
}
68