| Total Complexity | 44 |
| Total Lines | 417 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like SingUp often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SingUp, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class SingUp extends AbstractionController |
||
| 17 | { |
||
| 18 | use \Drone\Error\ErrorTrait; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var UsersEntity |
||
| 22 | */ |
||
| 23 | private $usersEntity; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @return UsersEntity |
||
| 27 | */ |
||
| 28 | private function getUsersEntity() |
||
| 29 | { |
||
| 30 | if (!is_null($this->usersEntity)) |
||
| 31 | return $this->usersEntity; |
||
| 32 | |||
| 33 | $this->usersEntity = new EntityAdapter(new UserTbl(new User())); |
||
| 34 | |||
| 35 | return $this->usersEntity; |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Checks user session and redirect to other module if exists any active session |
||
| 40 | * |
||
| 41 | * @return null |
||
| 42 | */ |
||
| 43 | private function checkSession() |
||
| 44 | { |
||
| 45 | $config = include 'module/Auth/config/user.config.php'; |
||
| 46 | $method = $config["authentication"]["method"]; |
||
| 47 | $key = $config["authentication"]["key"]; |
||
| 48 | |||
| 49 | switch ($method) |
||
| 50 | { |
||
| 51 | case '_COOKIE': |
||
| 52 | |||
| 53 | if (array_key_exists($key, $_COOKIE) || !empty($_COOKIE[$key])) |
||
| 54 | { |
||
| 55 | if (array_key_exists("CR_VAR_URL_REJECTED", $_SESSION) || !empty($_SESSION["CR_VAR_URL_REJECTED"])) |
||
| 56 | header("location: " . $_SESSION["CR_VAR_URL_REJECTED"]); |
||
| 57 | else |
||
| 58 | header("location: " . $this->basePath . "/public/" . $config["redirect"]); |
||
| 59 | } |
||
| 60 | |||
| 61 | break; |
||
| 62 | |||
| 63 | case '_SESSION': |
||
| 64 | |||
| 65 | if (array_key_exists($key, $_SESSION) || !empty($_SESSION[$key])) |
||
| 66 | { |
||
| 67 | if (array_key_exists("CR_VAR_URL_REJECTED", $_SESSION) || !empty($_SESSION["CR_VAR_URL_REJECTED"])) |
||
| 68 | header("location: " . $_SESSION["CR_VAR_URL_REJECTED"]); |
||
| 69 | else |
||
| 70 | header("location: " . $this->basePath . "/public/" . $config["redirect"]); |
||
| 71 | } |
||
| 72 | |||
| 73 | break; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Shows register form |
||
| 79 | * |
||
| 80 | * @return array |
||
| 81 | */ |
||
| 82 | public function index() |
||
| 83 | { |
||
| 84 | # STANDARD VALIDATIONS [check method] |
||
| 85 | if (!$this->isGet()) |
||
| 86 | { |
||
| 87 | $http = new Http(); |
||
| 88 | $http->writeStatus($http::HTTP_METHOD_NOT_ALLOWED); |
||
| 89 | |||
| 90 | die('Error ' . $http::HTTP_METHOD_NOT_ALLOWED .' (' . $http->getStatusText($http::HTTP_METHOD_NOT_ALLOWED) . ')!!'); |
||
| 91 | } |
||
| 92 | |||
| 93 | $this->checkSession(); |
||
| 94 | |||
| 95 | return []; |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Does register process |
||
| 100 | * |
||
| 101 | * @return array |
||
| 102 | */ |
||
| 103 | public function attemp() |
||
| 303 | } |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Does email checking |
||
| 307 | * |
||
| 308 | * @return array |
||
| 309 | */ |
||
| 310 | public function verifyEmail() |
||
| 311 | { |
||
| 312 | # data to send |
||
| 313 | $data = []; |
||
| 314 | |||
| 315 | # TRY-CATCH-BLOCK |
||
| 316 | try { |
||
| 317 | |||
| 318 | # STANDARD VALIDATIONS [check method] |
||
| 319 | if (!$this->isGet()) |
||
| 320 | { |
||
| 321 | $http = new Http(); |
||
| 322 | $http->writeStatus($http::HTTP_METHOD_NOT_ALLOWED); |
||
| 323 | |||
| 324 | die('Error ' . $http::HTTP_METHOD_NOT_ALLOWED .' (' . $http->getStatusText($http::HTTP_METHOD_NOT_ALLOWED) . ')!!'); |
||
| 325 | } |
||
| 326 | |||
| 327 | # STANDARD VALIDATIONS [check needed arguments] |
||
| 328 | $needles = ['token', 'user']; |
||
| 329 | |||
| 330 | array_walk($needles, function($item) { |
||
| 331 | if (!array_key_exists($item, $_GET)) |
||
| 332 | { |
||
| 333 | $http = new Http(); |
||
| 334 | $http->writeStatus($http::HTTP_BAD_REQUEST); |
||
| 335 | |||
| 336 | die('Error ' . $http::HTTP_BAD_REQUEST .' (' . $http->getStatusText($http::HTTP_BAD_REQUEST) . ')!!'); |
||
| 337 | } |
||
| 338 | }); |
||
| 339 | |||
| 340 | # catch arguments |
||
| 341 | $token = $_GET["token"]; |
||
| 342 | $user = $_GET["user"]; |
||
| 343 | |||
| 344 | $row = $this->getUsersEntity()->select([ |
||
| 345 | "USERNAME" => $user, |
||
| 346 | "TOKEN" => $token |
||
| 347 | ]); |
||
| 348 | |||
| 349 | if (!count($row)) |
||
| 350 | throw new \Drone\Exception\Exception("Token has expired or username does not exists!."); |
||
| 351 | |||
| 352 | $user = array_shift($row); |
||
| 353 | |||
| 354 | if ($user->USER_STATE_ID <> 1) |
||
| 355 | throw new \Drone\Exception\Exception("This email address had verified before!.", 300); |
||
| 356 | |||
| 357 | $user->USER_STATE_ID = 2; |
||
| 358 | |||
| 359 | $this->getUsersEntity()->update($user, [ |
||
| 360 | "USER_ID" => $user->USER_ID |
||
| 361 | ]); |
||
| 362 | |||
| 363 | # SUCCESS-MESSAGE |
||
| 364 | $data["process"] = "success"; |
||
| 365 | } |
||
| 366 | catch (\Drone\Exception\Exception $e) |
||
| 367 | { |
||
| 368 | # ERROR-MESSAGE |
||
| 369 | $data["process"] = "warning"; |
||
| 370 | $data["message"] = $e->getMessage(); |
||
| 371 | } |
||
| 372 | catch (\Exception $e) |
||
| 373 | { |
||
| 374 | $file = str_replace('\\', '', __CLASS__); |
||
| 375 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
||
| 376 | |||
| 377 | # stores the error code |
||
| 378 | if (($errorCode = $storage->store($e)) === false) |
||
| 379 | { |
||
| 380 | $errors = $storage->getErrors(); |
||
| 381 | |||
| 382 | # if error storing is not possible, handle it (internal app error) |
||
| 383 | $this->handleErrors($errors, __METHOD__); |
||
| 384 | } |
||
| 385 | |||
| 386 | # errors retrived by the use of ErrorTrait |
||
| 387 | if (count($this->getErrors())) |
||
| 388 | $this->handleErrors($this->getErrors(), __METHOD__); |
||
| 389 | |||
| 390 | $data["code"] = $errorCode; |
||
| 391 | $data["message"] = $e->getMessage(); |
||
| 392 | |||
| 393 | $config = include 'config/application.config.php'; |
||
| 394 | $data["dev_mode"] = $config["environment"]["dev_mode"]; |
||
| 395 | |||
| 396 | # redirect view |
||
| 397 | $this->setMethod('error'); |
||
| 398 | |||
| 399 | return $data; |
||
| 400 | } |
||
| 401 | |||
| 402 | return $data; |
||
| 403 | } |
||
| 404 | |||
| 405 | private function handleErrors(Array $errors, $method) |
||
| 433 | } |
||
| 434 | } |
||
| 435 | } |
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