Issues (69)

src/ControllerIP/IpController.php (6 issues)

1
<?php
2
namespace Moody\ControllerIP;
3
4
use Anax\Commons\ContainerInjectableInterface;
5
use Anax\Commons\ContainerInjectableTrait;
6
7
// use Anax\Route\Exception\ForbiddenException;
8
// use Anax\Route\Exception\NotFoundException;
9
// use Anax\Route\Exception\InternalErrorException;
10
11
/**
12
 * A sample controller to show how a controller class can be implemented.
13
 * The controller will be injected with $di if implementing the interface
14
 * ContainerInjectableInterface, like this sample class does.
15
 * The controller is mounted on a particular route and can then handle all
16
 * requests for that mount point.
17
 *
18
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
19
 */
20
class IpController implements ContainerInjectableInterface
21
{
22
    use ContainerInjectableTrait;
23
24
    private $ipAddress;
25
    private $object;
26
27
28 2
    public function result($ipAddress, $object) : string
29
    {
30 2
        if ($object->getProtocol($ipAddress)) {
31 1
            return "The IP $ipAddress is a valid " . $object->getProtocol($ipAddress) ." address." ;
32
        }
33 1
        return "The IP $ipAddress is not a valid ip-Address.";
34
    }
35
36 1
    public function indexAction() : object
37
    {
38
        // Deal with the action and return a response.
39 1
        $protocol =  null;
0 ignored issues
show
The assignment to $protocol is dead and can be removed.
Loading history...
40 1
        $host = null;
0 ignored issues
show
The assignment to $host is dead and can be removed.
Loading history...
41 1
        $address = null;
0 ignored issues
show
The assignment to $address is dead and can be removed.
Loading history...
42
43 1
        $title = "Ip validator";
44 1
        $page = $this->di->get("page");
45 1
        $request = $this->di->get("request");
46 1
        $this->ipAddress = $request->getGet("ip");
47 1
        $ip = $this->ipAddress;
0 ignored issues
show
The assignment to $ip is dead and can be removed.
Loading history...
48
49 1
        $this->object = new IpValidate();
50 1
        $protocol = $this->result($this->ipAddress, $this->object);
51 1
        $host = $this->object->getDomain($this->ipAddress);
52 1
        $address = $this->object->getAddress($this->ipAddress);
53 1
        $ip = $this->object->getCurrentIp($this->ipAddress);
0 ignored issues
show
The call to Moody\ControllerIP\IpValidate::getCurrentIp() has too many arguments starting with $this->ipAddress. ( Ignorable by Annotation )

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

53
        /** @scrutinizer ignore-call */ 
54
        $ip = $this->object->getCurrentIp($this->ipAddress);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
54 1
        $Domain = $this->object->getDomain($this->ipAddress);
55
56
57 1
        $data["ip"] = $ip;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
58 1
        $data["protocol"] = $protocol;
59 1
        $data["host"] = $host;
60 1
        $data["address"] = $address;
61 1
        $data["Domain"] = $Domain;
62
63
64 1
        $page->add("id/index", $data);
65 1
        return $page->render([
66 1
            "title" => $title,
67
        ]);
68
    }
69
}
70