Conditions | 10 |
Paths | 12 |
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 |
||
105 | 'Last login fields failed to be updated for user "%s" (%s)', |
||
106 | $userId, |
||
107 | $userClass |
||
108 | )); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | return $result; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Updates the user's password hash. |
||
117 | * |
||
118 | * @param AuthenticatableInterface $user The user to update. |
||
119 | * @param string $password The plain-text password to hash. |
||
120 | * @param boolean $update Whether to persist changes to storage. |
||
121 | * @throws InvalidArgumentException If the password is invalid. |
||
122 | * @return boolean Returns TRUE if the password was changed, or FALSE otherwise. |
||
123 | */ |
||
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) { |
||
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.