Issues (11)

src/Validate/ValidateIpController.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Bjos\Validate;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
// use Anax\Route\Exception\ForbiddenException;
9
// use Anax\Route\Exception\NotFoundException;
10
// use Anax\Route\Exception\InternalErrorException;
11
12
/**
13
 * Controller to validate IP address.
14
 *
15
 */
16
class ValidateIpController implements ContainerInjectableInterface
17
{
18
    use ContainerInjectableTrait;
19
20
    /**
21
     * This is the index method action, it handles:
22
     * IP validation of the queryparameter ip.
23
     *
24
     * @return object
25
     */
26 3
    public function indexAction() : object
27
    {
28 3
        $title = "Validate IP";
29 3
        $valid = null;
30 3
        $type = null;
31 3
        $host = null;
32 3
        $page = $this->di->get("page");
33 3
        $ipAdr = $this->di->request->getGet("ip");
0 ignored issues
show
Accessing request on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
34
35 3
        if ($ipAdr) {
36 3
            if (filter_var($ipAdr, FILTER_VALIDATE_IP)) {
37 2
                $valid = "True";
38 2
                $host = gethostbyaddr($ipAdr);
39
            } else {
40 1
                $valid = "False";
41
            }
42
43 3
            if ($valid === "True") {
44 2
                if (filter_var($ipAdr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
45 1
                    $type = "IPV4";
46 1
                } elseif (filter_var($ipAdr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
47 1
                    $type = "IPV6";
48
                }
49
            }
50
        }
51
52 3
        $page->add("bjos/validate-ip/index", [
53 3
            "valid" => $valid,
54 3
            "ip" => $ipAdr,
55 3
            "type" => $type,
56 3
            "host" => $host
57
        ]);
58
59 3
        $page->add("bjos/validate-ip/ip-json");
60
61 3
        return $page->render([
62 3
            "title" => $title
63
        ]);
64
    }
65
}
66