Conditions | 13 |
Paths | 322 |
Total Lines | 166 |
Code Lines | 91 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
35 | public function init(AbstractionController $c) |
||
36 | { |
||
37 | $config = $this->getUserConfig(); |
||
38 | |||
39 | $_config = ArrayDimension::toUnidimensional($config, "_"); |
||
40 | |||
41 | $this->setTranslator($c); |
||
42 | |||
43 | $app_config = include 'config/application.config.php'; |
||
44 | $global_config = include 'config/global.config.php'; |
||
45 | |||
46 | /** LAST REQUESTED URI : |
||
47 | * The last REQUEST_URI registered by $_SERVER. This session var is useful to redirect to the last URI requested |
||
48 | * when users log in. It should be an unique session id for the app to prevent bad redirections with other projects. |
||
49 | */ |
||
50 | # save only no XmlHttpRequest! |
||
51 | if (!$c->isXmlHttpRequest()) |
||
52 | $_SESSION["last_uri_" . $global_config["project"]["id"]] = $_SERVER["REQUEST_URI"]; |
||
53 | |||
54 | # config constraints |
||
55 | $components = [ |
||
56 | "attributes" => [ |
||
57 | "project_name" => [ |
||
58 | "required" => true, |
||
59 | "type" => "text", |
||
60 | "minlength" => 2, |
||
61 | "maxlength" => 60 |
||
62 | ], |
||
63 | "authentication_method" => [ |
||
64 | "required" => true, |
||
65 | "type" => "text" |
||
66 | ], |
||
67 | "authentication_key" => [ |
||
68 | "required" => true, |
||
69 | "type" => "text", |
||
70 | "minlength" => 1 |
||
71 | ], |
||
72 | "database_prefix" => [ |
||
73 | "required" => false, |
||
74 | "type" => "text" |
||
75 | ], |
||
76 | "redirect" => [ |
||
77 | "required" => true, |
||
78 | "type" => "text" |
||
79 | ] |
||
80 | ], |
||
81 | ]; |
||
82 | |||
83 | $options = [ |
||
84 | "project" => [ |
||
85 | "label" => "project -> name" |
||
86 | ], |
||
87 | "authentication_method" => [ |
||
88 | "label" => "authentication -> method", |
||
89 | "validators" => [ |
||
90 | "InArray" => ["haystack" => ['_COOKIE', '_SESSION']] |
||
91 | ] |
||
92 | ], |
||
93 | "authentication_key" => [ |
||
94 | "label" => "authentication -> key", |
||
95 | ], |
||
96 | "database_prefix" => [ |
||
97 | "label" => "database -> prefix" |
||
98 | ], |
||
99 | "redirect" => [ |
||
100 | "label" => "redirect" |
||
101 | ], |
||
102 | ]; |
||
103 | |||
104 | $form = new Form($components); |
||
105 | $form->fill($_config); |
||
106 | |||
107 | $validator = new FormValidator($form, $options); |
||
108 | $validator->validate(); |
||
109 | |||
110 | $data["validator"] = $validator; |
||
111 | |||
112 | try |
||
113 | { |
||
114 | if (!$validator->isValid()) |
||
115 | { |
||
116 | $data["messages"] = $validator->getMessages(); |
||
117 | throw new \Exception("Module config errros in user.config!", 300); |
||
118 | } |
||
119 | |||
120 | $redirect = $config["redirect"]; |
||
121 | $method = $config["authentication"]["method"]; |
||
122 | $key = $config["authentication"]["key"]; |
||
123 | |||
124 | $username_credential = null; |
||
125 | |||
126 | switch ($method) |
||
127 | { |
||
128 | case '_COOKIE': |
||
129 | |||
130 | if (!array_key_exists($key, $_COOKIE) || empty($_COOKIE[$key])) |
||
131 | { |
||
132 | # stops current controller execution |
||
133 | $c->stopExecution(false); |
||
134 | |||
135 | header("location: " . $c->getBasePath() . "/public/" . $redirect); |
||
136 | } |
||
137 | else |
||
138 | $username_credential = $_COOKIE[$key]; |
||
139 | |||
140 | break; |
||
141 | |||
142 | case '_SESSION': |
||
143 | |||
144 | if (!array_key_exists($key, $_SESSION) || empty($_SESSION[$key])) |
||
145 | { |
||
146 | # stops current controller execution |
||
147 | $c->stopExecution(false); |
||
148 | |||
149 | header("location: " . $c->getBasePath() . "/public/" . $redirect); |
||
150 | } |
||
151 | else |
||
152 | $username_credential = $_SESSION[$key]; |
||
153 | |||
154 | break; |
||
155 | } |
||
156 | |||
157 | # check inactivity (change user state to inactive while he's logged) |
||
158 | $user = $this->getUserAdapter()->getTableGateway()->getUserByUsernameCredential($username_credential); |
||
159 | |||
160 | $config = include 'module/Auth/config/user.config.php'; |
||
161 | $state_field = $config["authentication"]["gateway"]["table_info"]["columns"]["state_field"]; |
||
162 | $active_state = $config["authentication"]["gateway"]["table_info"]["column_values"]["state_field"]["user_active"]; |
||
163 | |||
164 | if ($user->{$state_field} != $active_state) |
||
165 | throw new \Exception("The user has been inactived!. Please log-in again."); |
||
166 | } |
||
167 | catch (\Exception $e) |
||
168 | { |
||
169 | $file = str_replace('\\', '', __CLASS__); |
||
170 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
||
171 | |||
172 | # stores the error code |
||
173 | if (($errorCode = $storage->store($e)) === false) |
||
174 | { |
||
175 | $errors = $storage->getErrors(); |
||
176 | |||
177 | # if error storing is not possible, handle it (internal app error) |
||
178 | //$this->handleErrors($errors, __METHOD__); |
||
179 | } |
||
180 | |||
181 | $data["code"] = $errorCode; |
||
182 | $data["message"] = $e->getMessage(); |
||
183 | |||
184 | $data["dev_mode"] = $app_config["environment"]["dev_mode"]; |
||
185 | |||
186 | # stops current controller execution |
||
187 | $c->stopExecution(false); |
||
188 | |||
189 | # loads error view |
||
190 | $layoutManager = new Layout(); |
||
191 | $layoutManager->setBasePath($c->getBasePath()); |
||
192 | |||
193 | $layoutManager->setView($this, "validation"); |
||
194 | $layoutManager->setParams($data); |
||
195 | |||
196 | # for AJAX requests! |
||
197 | if ($c->isXmlHttpRequest()) |
||
198 | $layoutManager->content(); |
||
199 | else |
||
200 | $layoutManager->fromTemplate($this, 'blank'); |
||
201 | } |
||
235 | } |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths