Issues (12)

src/Controller/IpVerifierController.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Linder\Controller;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Linder\Model\IpVerifier;
8
9
/**
10
 * A controller that handles a get request
11
 * and returns if its a valid ip or not.
12
 * @return Object
13
 */
14
class IpVerifierController implements ContainerInjectableInterface
15
{
16
    use ContainerInjectableTrait;
17
18
    /**
19
     * This is the index method action, it handles:
20
     *
21
     * @return object
22
     */
23 1
    public function indexAction() : object
24
    {
25 1
        $page = $this->di->get("page");
26
27 1
        $ip = $this->di->request->getGet("ip") ?: $this->di->request->getServer("REMOTE_ADDR");
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...
28
29 1
        $res = $this->di->get("ipverifier")->getJson($ip);
30
31
        $data = [
32 1
            "ip" => $ip,
33 1
            "domain" => $res["domain"],
34 1
            "protocol" => $res["type"],
35 1
            "lat" => $res["latitude"],
36 1
            "lon" => $res["longitude"],
37 1
            "country" => $res["country_name"],
38 1
            "city" => $res["city"]
39
        ];
40
41 1
        $page->add("ipverifier/main", $data);
42
43 1
        return $page->render([
44 1
            "title" => "Ipverifier",
45
        ]);
46
    }
47
}
48