| Conditions | 5 |
| Paths | 9 |
| Total Lines | 54 |
| Code Lines | 32 |
| 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 |
||
| 37 | public function register(Request $request, Response $response) |
||
| 38 | { |
||
| 39 | if ($request->isPost()) { |
||
| 40 | $username = $request->getParam('username'); |
||
| 41 | $email = $request->getParam('email'); |
||
| 42 | $password = $request->getParam('password'); |
||
| 43 | |||
| 44 | $this->validator->request($request, [ |
||
| 45 | 'username' => V::length(3, 25)->alnum('_')->noWhitespace(), |
||
| 46 | 'email' => V::noWhitespace()->email(), |
||
| 47 | 'password' => [ |
||
| 48 | 'rules' => V::noWhitespace()->length(6, 25), |
||
| 49 | 'messages' => [ |
||
| 50 | 'length' => 'The password length must be between {{minValue}} and {{maxValue}} characters' |
||
| 51 | ] |
||
| 52 | ], |
||
| 53 | 'password_confirm' => [ |
||
| 54 | 'rules' => V::equals($password), |
||
| 55 | 'messages' => [ |
||
| 56 | 'equals' => 'Passwords don\'t match' |
||
| 57 | ] |
||
| 58 | ] |
||
| 59 | ]); |
||
| 60 | |||
| 61 | if ($this->auth->findByCredentials(['login' => $username])) { |
||
| 62 | $this->validator->addError('username', 'This username is already used.'); |
||
| 63 | } |
||
| 64 | |||
| 65 | if ($this->auth->findByCredentials(['login' => $email])) { |
||
| 66 | $this->validator->addError('email', 'This email is already used.'); |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($this->validator->isValid()) { |
||
| 70 | $role = $this->auth->findRoleByName('User'); |
||
| 71 | |||
| 72 | $user = $this->auth->registerAndActivate([ |
||
| 73 | 'username' => $username, |
||
| 74 | 'email' => $email, |
||
| 75 | 'password' => $password, |
||
| 76 | 'permissions' => [ |
||
| 77 | 'user.delete' => 0 |
||
| 78 | ] |
||
| 79 | ]); |
||
| 80 | |||
| 81 | $role->users()->attach($user); |
||
| 82 | |||
| 83 | $this->flash('success', 'Your account has been created.'); |
||
| 84 | |||
| 85 | return $this->redirect($response, 'login'); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | return $this->view->render($response, 'Auth/register.twig'); |
||
| 90 | } |
||
| 91 | |||
| 99 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: