| Conditions | 9 |
| Paths | 14 |
| Total Lines | 56 |
| 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 |
||
| 124 | protected function changeUserPassword(AuthenticatableInterface $user, $password, $update = true) |
||
| 125 | { |
||
| 126 | if (!($user instanceof UserInterface)) { |
||
| 127 | return parent::changeUserPassword($user, $password); |
||
| 128 | } |
||
| 129 | |||
| 130 | if (!$this->validateAuthPassword($password)) { |
||
| 131 | throw new InvalidArgumentException( |
||
| 132 | 'Can not reset password: password is invalid' |
||
| 133 | ); |
||
| 134 | } |
||
| 135 | |||
| 136 | $userId = $user->getAuthId(); |
||
| 137 | |||
| 138 | if ($update && $userId) { |
||
| 139 | $userClass = get_class($user); |
||
| 140 | |||
| 141 | $this->logger->info(sprintf( |
||
| 142 | 'Changing password for user "%s" (%s)', |
||
| 143 | $userId, |
||
| 144 | $userClass |
||
| 145 | )); |
||
| 146 | } |
||
| 147 | |||
| 148 | $passwordKey = $user->getAuthPasswordKey(); |
||
| 149 | |||
| 150 | $user[$passwordKey] = password_hash($password, PASSWORD_DEFAULT); |
||
| 151 | $user['lastPasswordDate'] = 'now'; |
||
| 152 | $user['lastPasswordIp'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; |
||
| 153 | |||
| 154 | if ($update && $userId) { |
||
| 155 | $result = $user->update([ |
||
| 156 | $passwordKey, |
||
| 157 | 'last_password_date', |
||
| 158 | 'last_password_ip', |
||
| 159 | ]); |
||
| 160 | |||
| 161 | if ($result) { |
||
| 162 | $this->logger->notice(sprintf( |
||
| 163 | 'Password was changed for user "%s" (%s)', |
||
| 164 | $userId, |
||
| 165 | $userClass |
||
| 166 | )); |
||
| 167 | } else { |
||
| 168 | $this->logger->warning(sprintf( |
||
| 169 | 'Password failed to be changed for user "%s" (%s)', |
||
| 170 | $userId, |
||
| 171 | $userClass |
||
| 172 | )); |
||
| 173 | } |
||
| 174 | |||
| 175 | return $result; |
||
| 176 | } |
||
| 177 | |||
| 178 | return true; |
||
| 179 | } |
||
| 180 | } |
||
| 181 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.