| Total Complexity | 43 |
| Total Lines | 368 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like LogIn 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 LogIn, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class LogIn extends AbstractionController |
||
| 19 | { |
||
| 20 | use \Drone\Error\ErrorTrait; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var EntityAdapter |
||
| 24 | */ |
||
| 25 | private $userAdapter; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var EntityAdapter |
||
| 29 | */ |
||
| 30 | private $userRoleAdapter; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var EntityAdapter |
||
| 34 | */ |
||
| 35 | private $dbUserRoleAdapter; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return EntityAdapter |
||
| 39 | */ |
||
| 40 | private function getUserAdapter() |
||
| 41 | { |
||
| 42 | if (!is_null($this->userAdapter)) |
||
| 43 | return $this->userAdapter; |
||
| 44 | |||
| 45 | $this->userAdapter = new EntityAdapter(new TableGateway(new User())); |
||
| 46 | |||
| 47 | return $this->userAdapter; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return EntityAdapter |
||
| 52 | */ |
||
| 53 | private function getUserRoleAdapter() |
||
| 54 | { |
||
| 55 | if (!is_null($this->userRoleAdapter)) |
||
| 56 | return $this->userRoleAdapter; |
||
| 57 | |||
| 58 | $this->userRoleAdapter = new EntityAdapter(new TableGateway(new UserRole())); |
||
| 59 | |||
| 60 | return $this->userRoleAdapter; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return EntityAdapter |
||
| 65 | */ |
||
| 66 | private function getDbUserRoleAdapter() |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Checks user session and redirect to other module if exists any active session |
||
| 78 | * |
||
| 79 | * @return null |
||
| 80 | */ |
||
| 81 | private function checkSession() |
||
| 82 | { |
||
| 83 | $config = include 'module/Auth/config/user.config.php'; |
||
| 84 | $method = $config["authentication"]["method"]; |
||
| 85 | $key = $config["authentication"]["key"]; |
||
| 86 | |||
| 87 | $global_config = include 'config/global.config.php'; |
||
| 88 | |||
| 89 | /** URL TO REDIRECT: |
||
| 90 | * |
||
| 91 | * By default if there isn't a session active, it will be redirected to the module in the user config file ($config["redirect"]). |
||
| 92 | * If a last URI requested exists, it will be redirecto to it. |
||
| 93 | * |
||
| 94 | * Other modules must have the following line of code inside init method to ensure last uri redirection. |
||
| 95 | * $_SESSION["last_uri_" . $global_config["project"]["id"]] = $_SERVER["REQUEST_URI"]; |
||
| 96 | * It should be an unique session id for the app to prevent bad redirections with other projects. |
||
| 97 | */ |
||
| 98 | if (array_key_exists("last_uri_" . $global_config["project"]["id"], $_SESSION) || !empty($_SESSION["last_uri_" . $global_config["project"]["id"]])) |
||
| 99 | $location = $_SESSION["last_uri_" . $global_config["project"]["id"]]; |
||
| 100 | else |
||
| 101 | $location = $this->getBasePath() . "/public/" . $config["redirect"]; |
||
| 102 | |||
| 103 | switch ($method) |
||
| 104 | { |
||
| 105 | case '_COOKIE': |
||
| 106 | |||
| 107 | if (array_key_exists($key, $_COOKIE) || !empty($_COOKIE[$key])) |
||
| 108 | header("location: " . $location); |
||
| 109 | |||
| 110 | break; |
||
| 111 | |||
| 112 | case '_SESSION': |
||
| 113 | |||
| 114 | if (array_key_exists($key, $_SESSION) || !empty($_SESSION[$key])) |
||
| 115 | header("location: " . $location); |
||
| 116 | |||
| 117 | break; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Shows login form |
||
| 123 | * |
||
| 124 | * @return array |
||
| 125 | */ |
||
| 126 | public function index() |
||
| 127 | { |
||
| 128 | # STANDARD VALIDATIONS [check method] |
||
| 129 | if (!$this->isGet()) |
||
| 130 | { |
||
| 131 | $http = new Http(); |
||
| 132 | $http->writeStatus($http::HTTP_METHOD_NOT_ALLOWED); |
||
| 133 | |||
| 134 | die('Error ' . $http::HTTP_METHOD_NOT_ALLOWED .' (' . $http->getStatusText($http::HTTP_METHOD_NOT_ALLOWED) . ')!!'); |
||
| 135 | } |
||
| 136 | |||
| 137 | $this->checkSession(); |
||
| 138 | |||
| 139 | return []; |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Checks user credentials |
||
| 144 | * |
||
| 145 | * @return array |
||
| 146 | */ |
||
| 147 | public function attemp() |
||
| 356 | } |
||
| 357 | |||
| 358 | private function handleErrors(Array $errors, $method) |
||
| 386 | } |
||
| 387 | } |
||
| 388 | } |
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