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