| Conditions | 4 |
| Paths | 4 |
| Total Lines | 52 |
| 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 namespace VojtaSvoboda\CodeLogin\Components; |
||
| 86 | private function doSignin() |
||
| 87 | { |
||
| 88 | /* |
||
| 89 | * Validate input |
||
| 90 | */ |
||
| 91 | $data = post(); |
||
| 92 | |||
| 93 | $rules = []; |
||
| 94 | $rules['code'] = 'required|min:2'; |
||
| 95 | |||
| 96 | $messages = []; |
||
| 97 | $messages['required'] = trans('vojtasvoboda.codelogin::lang.form.required'); |
||
| 98 | |||
| 99 | $validation = Validator::make($data, $rules, $messages); |
||
| 100 | if ($validation->fails()) { |
||
| 101 | throw new ValidationException($validation); |
||
| 102 | } |
||
| 103 | |||
| 104 | /* |
||
| 105 | * Find user by password |
||
| 106 | */ |
||
| 107 | $users = new UserRepository(); |
||
| 108 | $userToLog = $users->getUserByPassword(array_get($data, 'code')); |
||
| 109 | if ($userToLog === null) { |
||
| 110 | $exception = new ValidationException([ 'code' => trans('vojtasvoboda.codelogin::lang.form.wrong_code') ]); |
||
| 111 | throw $exception; |
||
| 112 | } |
||
| 113 | |||
| 114 | /* |
||
| 115 | * Authenticate user |
||
| 116 | */ |
||
| 117 | $remember = true; |
||
| 118 | $user = Auth::authenticate([ |
||
| 119 | 'login' => $userToLog->email, |
||
| 120 | 'password' => array_get($data, 'code') |
||
| 121 | ], $remember); |
||
| 122 | |||
| 123 | /* |
||
| 124 | * Event just for backward compatibility. It's more then recommand use |
||
| 125 | * standard rainlab.user.login event - see readme. |
||
| 126 | */ |
||
| 127 | Event::fire('vojtasvoboda.codelogin.afterlogin', [$user]); |
||
| 128 | |||
| 129 | /* |
||
| 130 | * Redirect to the intended page after successful sign in |
||
| 131 | */ |
||
| 132 | $redirectUrl = $this->pageUrl($this->property('redirect')); |
||
| 133 | |||
| 134 | if ($redirectUrl = post('redirect', $redirectUrl)) { |
||
| 135 | return Redirect::intended($redirectUrl); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 |