1 | <?php |
||||||
2 | |||||||
3 | namespace Moody\ControllerIP; |
||||||
4 | |||||||
5 | use Anax\Commons\ContainerInjectableInterface; |
||||||
6 | use Anax\Commons\ContainerInjectableTrait; |
||||||
7 | |||||||
8 | /** |
||||||
9 | * A sample controller to show how a controller class can be implemented. |
||||||
10 | * The controller will be injected with $di if implementing the interface |
||||||
11 | * ContainerInjectableInterface, like this sample class does. |
||||||
12 | * The controller is mounted on a particular route and can then handle all |
||||||
13 | * requests for that mount point. |
||||||
14 | * |
||||||
15 | * @SuppressWarnings(PHPMD.TooManyPublicMethods) |
||||||
16 | */ |
||||||
17 | class JsonController implements ContainerInjectableInterface |
||||||
18 | { |
||||||
19 | use ContainerInjectableTrait; |
||||||
20 | |||||||
21 | private $ipAddress; |
||||||
22 | private $object; |
||||||
23 | |||||||
24 | |||||||
25 | 1 | public function indexAction() : object |
|||||
26 | { |
||||||
27 | 1 | $title = "Check IP with (JSON)"; |
|||||
28 | |||||||
29 | 1 | $page = $this->di->get("page"); |
|||||
30 | 1 | $request = $this->di->get("request"); |
|||||
31 | 1 | $json = null; |
|||||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||||||
32 | 1 | $this->ipAddress = $request->getGet("ip"); |
|||||
33 | 1 | $this->object = new IpValidate(); |
|||||
34 | |||||||
35 | 1 | $ip = $this->ipAddress; |
|||||
0 ignored issues
–
show
|
|||||||
36 | 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
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. ![]() |
|||||||
37 | 1 | $Domain = $this->object->getDomain($this->ipAddress); |
|||||
38 | |||||||
39 | |||||||
40 | |||||||
41 | 1 | $json = $this->ipJson($this->ipAddress, $this->object); |
|||||
42 | 1 | $data['json'] = $json; |
|||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
43 | 1 | $data["ip"] = $ip; |
|||||
44 | 1 | $data["Domain"] = $Domain; |
|||||
45 | |||||||
46 | 1 | $page->add("id/json", $data); |
|||||
47 | 1 | return $page->render([ |
|||||
48 | 1 | "title" => $title, |
|||||
49 | ]); |
||||||
50 | } |
||||||
51 | |||||||
52 | |||||||
53 | 2 | public function ipJson($ipAddress, $object) : array |
|||||
54 | { |
||||||
55 | $json = [ |
||||||
56 | 2 | "ip" => $ipAddress, |
|||||
57 | // "ip" => $ip, |
||||||
58 | |||||||
59 | 2 | "Protocol" => $object->getProtocol($ipAddress) ?? null, |
|||||
60 | 2 | "Domain" => $object->getDomain($ipAddress) ?? null, |
|||||
61 | 2 | "address" => $object->getAddress($ipAddress) ?? null, |
|||||
62 | ]; |
||||||
63 | 2 | return [$json]; |
|||||
64 | } |
||||||
65 | } |
||||||
66 |