| Conditions | 13 |
| Paths | 32 |
| Total Lines | 59 |
| Code Lines | 30 |
| 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 |
||
| 111 | protected function doSubmitAction() |
||
| 112 | { |
||
| 113 | try { |
||
| 114 | $sessionToken = $this->getSession()->getCsrfToken(); |
||
| 115 | $actionToken = filter_input(INPUT_POST, 'token'); |
||
| 116 | |||
| 117 | if (! $actionToken || ! $sessionToken->isValid($actionToken)) { |
||
| 118 | return; |
||
| 119 | } |
||
| 120 | |||
| 121 | $user = $this->user; |
||
| 122 | |||
| 123 | if (! $this->hasAuthenticatedUser() || ! $this->getAcl()->canEditEntity($this->getAuthenticatedUser(), $user)) { |
||
| 124 | return; |
||
| 125 | } |
||
| 126 | |||
| 127 | // Set the user name. |
||
| 128 | $user->set('name', filter_input(INPUT_POST, 'user_name'), true); |
||
| 129 | |||
| 130 | // Set the user email. |
||
| 131 | $user->set('email', filter_input(INPUT_POST, 'user_email'), true); |
||
| 132 | |||
| 133 | $duplicateUser = $this->getUserRepository()->findOneBy(['email' => $user->get('email'), 'status' => 'any']); |
||
| 134 | |||
| 135 | if (! empty($duplicateUser) && $duplicateUser->get('id') != $user->get('id')) { |
||
| 136 | throw new InvalidArgumentException(__('Please enter a unique user e-mail.')); |
||
| 137 | } |
||
| 138 | |||
| 139 | $userPass1 = filter_input(INPUT_POST, 'user_pass_1', FILTER_UNSAFE_RAW); |
||
| 140 | $userPass2 = filter_input(INPUT_POST, 'user_pass_2', FILTER_UNSAFE_RAW); |
||
| 141 | |||
| 142 | if (! empty($userPass1) xor ! empty($userPass2)) { |
||
| 143 | throw new InvalidArgumentException(__('Please enter the password twice.')); |
||
| 144 | } |
||
| 145 | |||
| 146 | if (! empty($userPass1) && ! empty($userPass2)) { |
||
| 147 | if ($userPass1 !== $userPass2) { |
||
| 148 | throw new InvalidArgumentException(__('Please enter the same password.')); |
||
| 149 | } |
||
| 150 | |||
| 151 | // Set the user password. |
||
| 152 | $user->set('pass', password_hash($userPass1, PASSWORD_BCRYPT), false); |
||
| 153 | } |
||
| 154 | |||
| 155 | // Set the user role. |
||
| 156 | if ($user->get('id') != $this->getAuthenticatedUser()->get('id')) { |
||
| 157 | $user->set('role', filter_input(INPUT_POST, 'user_role'), true); |
||
| 158 | } |
||
| 159 | |||
| 160 | $this->getEntityManager()->flush($user); |
||
| 161 | |||
| 162 | EBB\redirect( |
||
| 163 | EBB\addQueryArgs( |
||
| 164 | EBB\getEditUserURL($user->get('id')), |
||
| 165 | ['flag-edited' => true] |
||
| 166 | ) |
||
| 167 | ); |
||
| 168 | } catch (InvalidArgumentException $ex) { |
||
| 169 | Notices::addNotice('invalid_user_argument', $ex->getMessage()); |
||
| 170 | } |
||
| 173 |