| Conditions | 11 |
| Paths | 32 |
| Total Lines | 71 |
| Code Lines | 37 |
| 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 |
||
| 81 | protected function doSubmitAction() |
||
| 82 | { |
||
| 83 | try { |
||
| 84 | if (! $this->hasAuthenticatedUser() || ! $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'User', 'add')) { |
||
| 85 | return; |
||
| 86 | } |
||
| 87 | |||
| 88 | $sessionToken = $this->getSession()->getCsrfToken(); |
||
| 89 | $actionToken = filter_input(INPUT_POST, 'token'); |
||
| 90 | |||
| 91 | if (! $actionToken || ! $sessionToken->isValid($actionToken)) { |
||
| 92 | return; |
||
| 93 | } |
||
| 94 | |||
| 95 | $user = $this->user; |
||
| 96 | |||
| 97 | // Set the user name. |
||
| 98 | $user->set('name', filter_input(INPUT_POST, 'user_name'), true); |
||
| 99 | |||
| 100 | // Set the user email. |
||
| 101 | $user->set('email', filter_input(INPUT_POST, 'user_email'), true); |
||
| 102 | |||
| 103 | $duplicateUser = $this->getUserRepository()->findOneBy(['email' => $user->get('email'), 'status' => 'any']); |
||
| 104 | |||
| 105 | if (! empty($duplicateUser)) { |
||
| 106 | throw new InvalidArgumentException(__('Please enter a unique user e-mail.')); |
||
| 107 | } |
||
| 108 | |||
| 109 | $userPass1 = filter_input(INPUT_POST, 'user_pass_1', FILTER_UNSAFE_RAW); |
||
| 110 | $userPass2 = filter_input(INPUT_POST, 'user_pass_2', FILTER_UNSAFE_RAW); |
||
| 111 | |||
| 112 | if (empty($userPass1)) { |
||
| 113 | throw new InvalidArgumentException(__('Please enter the password.')); |
||
| 114 | } |
||
| 115 | |||
| 116 | if (empty($userPass2)) { |
||
| 117 | throw new InvalidArgumentException(__('Please confirm the password.')); |
||
| 118 | } |
||
| 119 | |||
| 120 | if ($userPass1 !== $userPass2) { |
||
| 121 | throw new InvalidArgumentException(__('Please enter the same password.')); |
||
| 122 | } |
||
| 123 | |||
| 124 | // Set the user password. |
||
| 125 | $user->set('pass', password_hash($userPass1, PASSWORD_BCRYPT), false); |
||
| 126 | |||
| 127 | // Set the user role. |
||
| 128 | $user->set('role', filter_input(INPUT_POST, 'user_role'), true); |
||
| 129 | |||
| 130 | // Set the user status. |
||
| 131 | if ($this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'User', 'activate')) { |
||
| 132 | $user->set('status', 'activated'); |
||
| 133 | } else { |
||
| 134 | $user->set('status', Options::getOption('new_user_status'), true); |
||
|
|
|||
| 135 | } |
||
| 136 | |||
| 137 | $this->getEntityManager()->persist($user); |
||
| 138 | $this->getEntityManager()->flush(); |
||
| 139 | |||
| 140 | $this->getEventManager()->getEventDispatcher()->dispatch('user.created', new GenericEvent($user)); |
||
| 141 | |||
| 142 | $added = $user->isExists(); |
||
| 143 | |||
| 144 | EBB\redirect( |
||
| 145 | EBB\addQueryArgs( |
||
| 146 | EBB\getAddUserURL(), |
||
| 147 | ['flag-added' => $added] |
||
| 148 | ) |
||
| 149 | ); |
||
| 150 | } catch (InvalidArgumentException $ex) { |
||
| 151 | Notices::addNotice('invalid_user_argument', $ex->getMessage()); |
||
| 152 | } |
||
| 155 |
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