Conditions | 14 |
Paths | 409 |
Total Lines | 211 |
Code Lines | 123 |
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 |
||
109 | public function attemp() |
||
110 | { |
||
111 | # data to send |
||
112 | $data = []; |
||
113 | |||
114 | # environment settings |
||
115 | $post = $this->getPost(); # catch $_POST |
||
116 | $this->setTerminal(true); # set terminal |
||
117 | |||
118 | # TRY-CATCH-BLOCK |
||
119 | try { |
||
120 | |||
121 | # STANDARD VALIDATIONS [check method] |
||
122 | if (!$this->isPost()) |
||
123 | { |
||
124 | $http = new Http(); |
||
125 | $http->writeStatus($http::HTTP_METHOD_NOT_ALLOWED); |
||
126 | |||
127 | die('Error ' . $http::HTTP_METHOD_NOT_ALLOWED .' (' . $http->getStatusText($http::HTTP_METHOD_NOT_ALLOWED) . ')!!'); |
||
128 | } |
||
129 | |||
130 | # STANDARD VALIDATIONS [check needed arguments] |
||
131 | $needles = ['username', 'email', 'password', 'password_confirm']; |
||
132 | |||
133 | array_walk($needles, function(&$item) use ($post) { |
||
134 | if (!array_key_exists($item, $post)) |
||
135 | { |
||
136 | $http = new Http(); |
||
137 | $http->writeStatus($http::HTTP_BAD_REQUEST); |
||
138 | |||
139 | die('Error ' . $http::HTTP_BAD_REQUEST .' (' . $http->getStatusText($http::HTTP_BAD_REQUEST) . ')!!'); |
||
140 | } |
||
141 | }); |
||
142 | |||
143 | $this->checkSession(); |
||
144 | |||
145 | if ($post["password"] !== $post["password_confirm"]) |
||
146 | throw new \Drone\Exception\Exception("The password fields are different!", 300); |
||
147 | |||
148 | $components = [ |
||
149 | "attributes" => [ |
||
150 | "username" => [ |
||
151 | "required" => true, |
||
152 | "type" => "text", |
||
153 | "minlength" => 4, |
||
154 | "maxlength" => 20 |
||
155 | ], |
||
156 | "email" => [ |
||
157 | "required" => true, |
||
158 | "type" => "text", |
||
159 | "minlength" => 4, |
||
160 | "maxlength" => 50 |
||
161 | ], |
||
162 | "password" => [ |
||
163 | "required" => true, |
||
164 | "type" => "text", |
||
165 | "minlength" => 4, |
||
166 | "maxlength" => 20 |
||
167 | ], |
||
168 | "password_confirm" => [ |
||
169 | "required" => true, |
||
170 | "type" => "text", |
||
171 | "minlength" => 4, |
||
172 | "maxlength" => 20 |
||
173 | ] |
||
174 | ], |
||
175 | ]; |
||
176 | |||
177 | $options = [ |
||
178 | "username" => [ |
||
179 | "label" => "Username", |
||
180 | "validators" => [ |
||
181 | "Alnum" => ["allowWhiteSpace" => false] |
||
182 | ] |
||
183 | ], |
||
184 | "email" => [ |
||
185 | "label" => "Email" |
||
186 | ], |
||
187 | "password" => [ |
||
188 | "label" => "Password" |
||
189 | ], |
||
190 | "password_confirm" => [ |
||
191 | "label" => "Password confirmation" |
||
192 | ] |
||
193 | ]; |
||
194 | |||
195 | $form = new Form($components); |
||
196 | $form->fill($post); |
||
197 | |||
198 | $validator = new FormValidator($form, $options); |
||
199 | $validator->validate(); |
||
200 | |||
201 | $data["validator"] = $validator; |
||
202 | |||
203 | # STANDARD VALIDATIONS [check argument constraints] |
||
204 | if (!$validator->isValid()) |
||
205 | { |
||
206 | $data["messages"] = $validator->getMessages(); |
||
207 | throw new \Drone\Exception\Exception("Form validation errors!", 300); |
||
208 | } |
||
209 | |||
210 | $config = include 'module/Auth/config/user.config.php'; |
||
211 | $username_str = $config["authentication"]["gateway"]["credentials"]["username"]; |
||
212 | $password_str = $config["authentication"]["gateway"]["credentials"]["password"]; |
||
213 | $state_field = $config["authentication"]["gateway"]["table_info"]["columns"]["state_field"]; |
||
214 | $id_field = $config["authentication"]["gateway"]["table_info"]["columns"]["id_field"]; |
||
215 | $email_field = $config["authentication"]["gateway"]["table_info"]["columns"]["email_field"]; |
||
216 | |||
217 | $pending_state = $config["authentication"]["gateway"]["table_info"]["column_values"]["state_field"]["pending_email"]; |
||
218 | $active_state = $config["authentication"]["gateway"]["table_info"]["column_values"]["state_field"]["user_active"]; |
||
219 | |||
220 | $rowset = $this->getUserAdapter()->select([ |
||
221 | $username_str => $post["username"] |
||
222 | ]); |
||
223 | |||
224 | if (count($rowset)) |
||
225 | throw new \Drone\Exception\Exception("This username already exists!", 300); |
||
226 | |||
227 | $bcrypt = new Bcrypt(); |
||
228 | $securePass = $bcrypt->create($post["password"]); |
||
229 | |||
230 | $t = base64_encode(time() . uniqid()); |
||
231 | $token = substr($t, 0, 30); |
||
232 | |||
233 | $this->getUserAdapter()->getTableGateway()->getDriver()->getDb()->beginTransaction(); |
||
234 | |||
235 | $data["mail"] = ($config["mail"]["checking"]["enabled"] == "Y") ? true : false; |
||
236 | |||
237 | $user = new User(); |
||
238 | |||
239 | $user->exchangeArray([ |
||
240 | $id_field => $this->getUserAdapter()->getTableGateway()->getNextId(), |
||
241 | $state_field => $data["mail"] ? $pending_state : $active_state, |
||
242 | $username_str => $post["username"], |
||
243 | $email_field => $post["email"], |
||
244 | "TOKEN" => $token, |
||
245 | $password_str => $securePass |
||
246 | ]); |
||
247 | |||
248 | $this->getUserAdapter()->insert($user); |
||
249 | |||
250 | $link = $_SERVER["REQUEST_SCHEME"] .'://'. $_SERVER["HTTP_HOST"] . $this->getBasePath() . "/public/Auth/SingUp/verifyEmail/user/" . $post["username"] . "/token/" . $token; |
||
251 | |||
252 | if ($data["mail"]) |
||
253 | { |
||
254 | $from = $config["mail"]["checking"]["from"]; |
||
255 | $host = $config["mail"]["host"]; |
||
256 | |||
257 | $mail = new Mail(); |
||
258 | $mail->setHost($host); |
||
259 | $subject = $this->translator->translate("Email checking") . "!"; |
||
260 | $body = $this->translator->translate("Your account has been registered") . "!." . |
||
261 | $this->translator->translate("Please click on the following link to confirm your account") . |
||
262 | "<br /><br /><a href='$link'>$link</a>."; |
||
263 | |||
264 | $success = $mail->send($from, $post["email"], $subject, $body); |
||
265 | |||
266 | if (!$success) |
||
267 | { |
||
268 | $errors = array_values($mail->getErrors()); |
||
269 | $err = array_shift($errors); |
||
270 | $this->getUserAdapter()->getTableGateway()->getDriver()->getDb()->rollback(); |
||
271 | throw new \Exception($err); |
||
272 | } |
||
273 | } |
||
274 | |||
275 | $this->getUserAdapter()->getTableGateway()->getDriver()->getDb()->endTransaction(); |
||
276 | |||
277 | $data["username"] = $post["username"]; |
||
278 | $data["email"] = $post["email"]; |
||
279 | |||
280 | # SUCCESS-MESSAGE |
||
281 | $data["process"] = "success"; |
||
282 | } |
||
283 | catch (\Drone\Exception\Exception $e) |
||
284 | { |
||
285 | # ERROR-MESSAGE |
||
286 | $data["process"] = "warning"; |
||
287 | $data["message"] = $e->getMessage(); |
||
288 | } |
||
289 | catch (\Exception $e) |
||
290 | { |
||
291 | $file = str_replace('\\', '', __CLASS__); |
||
292 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
||
293 | |||
294 | # stores the error code |
||
295 | if (($errorCode = $storage->store($e)) === false) |
||
296 | { |
||
297 | $errors = $storage->getErrors(); |
||
298 | |||
299 | # if error storing is not possible, handle it (internal app error) |
||
300 | $this->handleErrors($errors, __METHOD__); |
||
301 | } |
||
302 | |||
303 | # errors retrived by the use of ErrorTrait |
||
304 | if (count($this->getErrors())) |
||
305 | $this->handleErrors($this->getErrors(), __METHOD__); |
||
306 | |||
307 | $data["code"] = $errorCode; |
||
308 | $data["message"] = $e->getMessage(); |
||
309 | |||
310 | $config = include 'config/application.config.php'; |
||
311 | $data["dev_mode"] = $config["environment"]["dev_mode"]; |
||
312 | |||
313 | # redirect view |
||
314 | $this->setMethod('error'); |
||
315 | |||
316 | return $data; |
||
317 | } |
||
318 | |||
319 | return $data; |
||
320 | } |
||
461 | } |
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