Issues (33)

src/MeModule/ValidateIPController.php (4 issues)

1
<?php
2
3
namespace Hab\MeModule;
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 ValidateIPController 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 11
    public function initialize() : void
42
    {
43
        // Use to initialise member variables.
44 11
        $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 11
        $session = $this->di->get("session");
46 11
        if ($session->get("res")) {
47 4
            $this->res = $session->get("res");
48
        }
49 11
    }
50
51
52
53
    /**
54
     * Creates page and form for IP validation.
55
     * @return page
0 ignored issues
show
The type Hab\MeModule\page was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
56
     */
57 1
    public function indexActionGet() : object
58
    {
59
        $data = [
60 1
            "res" => $this->res,
61
        ];
62 1
        $title = "Validate IP";
63 1
        $page = $this->di->get("page");
64 1
        $page->add("MeModule/validate-ip", $data);
65
        // $namespaces=array();
66
        // foreach(get_declared_classes() as $name) {
67
        //     if(preg_match_all("@[^\\\]+(?=\\\)@iU", $name, $matches)) {
68
        //         $matches = $matches[0];
69
        //         $parent =&$namespaces;
70
        //         while(count($matches)) {
71
        //             $match = array_shift($matches);
72
        //             if(!isset($parent[$match]) && count($matches))
73
        //                 $parent[$match] = array();
74
        //             $parent =&$parent[$match];
75
76
        //         }
77
        //     }
78
        // }
79
80
        // print_r($namespaces);
81 1
        return $page->render([
82 1
            "title" => $title,
83
        ]);
84
    }
85
86
    /**
87
     * Reads post variables and sett result in session.
88
     * Redirects user back to form page. (/validate)
89
     * @return redirect
0 ignored issues
show
The type Hab\MeModule\redirect was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
90
     */
91 3
    public function checkActionPost() : object
92
    {
93 3
        $request = $this->di->get("request");
94 3
        $response = $this->di->get("response");
95 3
        $session = $this->di->get("session");
96 3
        $ip = $request->getPost("ip");
97
        // $test = $this->di->get("fetch");
98 3
        $validator = new \Hab\MeModule\ValidateIP($ip);
99 3
        $data = $validator->sendRes();
100 3
        $this->res["data"] = $data;
101
102 3
        $session->set("res", $this->res);
103 3
        return $response->redirect("validate");
104
    }
105
106
    /**
107
     * Resets session variable's response
108
     * @return redirect
109
     */
110 1
    public function resetActionPost() : object
111
    {
112 1
        $response = $this->di->get("response");
113 1
        $session = $this->di->get("session");
114
        // $session->destroy();
115
        // $session->start();
116 1
        $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...
117 1
        $session->set("res", $this->res);
118 1
        return $response->redirect("validate");
119
    }
120
}
121