diff --git a/src/Illuminate/Auth/Reminders/PasswordBroker.php b/src/Illuminate/Auth/Reminders/PasswordBroker.php index 6b914b46..86d14f6c 100755 --- a/src/Illuminate/Auth/Reminders/PasswordBroker.php +++ b/src/Illuminate/Auth/Reminders/PasswordBroker.php @@ -46,35 +46,35 @@ class PasswordBroker { * * @var \Illuminate\Auth\Reminders\ReminderRepositoryInterface $reminders */ - protected $reminders; + protected ReminderRepositoryInterface $reminders; /** * The user provider implementation. * * @var \Illuminate\Auth\UserProviderInterface */ - protected $users; + protected UserProviderInterface $users; /** * The mailer instance. * * @var \Illuminate\Mail\Mailer */ - protected $mailer; + protected Mailer $mailer; /** * The view of the password reminder e-mail. * * @var string */ - protected $reminderView; + protected string $reminderView; /** * The custom password validator callback. * * @var \Closure */ - protected $passwordValidator; + protected Closure $passwordValidator; /** * Create a new password broker instance. @@ -82,13 +82,13 @@ class PasswordBroker { * @param \Illuminate\Auth\Reminders\ReminderRepositoryInterface $reminders * @param \Illuminate\Auth\UserProviderInterface $users * @param \Illuminate\Mail\Mailer $mailer - * @param string $reminderView + * @param string $reminderView * @return void */ public function __construct(ReminderRepositoryInterface $reminders, - UserProviderInterface $users, - Mailer $mailer, - $reminderView) + UserProviderInterface $users, + Mailer $mailer, + string $reminderView) { $this->users = $users; $this->mailer = $mailer; @@ -103,14 +103,14 @@ public function __construct(ReminderRepositoryInterface $reminders, * @param \Closure $callback * @return string */ - public function remind(array $credentials, Closure $callback = null) + public function remind(array $credentials, Closure $callback = null): string { // First we will check to see if we found a user at the given credentials and // if we did not we will redirect back to this current URI with a piece of // "flash" data in the session to indicate to the developers the errors. $user = $this->getUser($credentials); - if (is_null($user)) + if ($user === null) { return self::INVALID_USER; } @@ -129,22 +129,24 @@ public function remind(array $credentials, Closure $callback = null) * Send the password reminder e-mail. * * @param \Illuminate\Auth\Reminders\RemindableInterface $user - * @param string $token - * @param \Closure $callback - * @return int + * @param string $token + * @param Closure $callback + * @return void */ - public function sendReminder(RemindableInterface $user, $token, Closure $callback = null) + public function sendReminder(RemindableInterface $user, string $token, Closure $callback = null): void { // We will use the reminder view that was given to the broker to display the // password reminder e-mail. We'll pass a "token" variable into the views // so that it may be displayed for an user to click for password reset. $view = $this->reminderView; - return $this->mailer->send($view, compact('token', 'user'), function($m) use ($user, $token, $callback) + $this->mailer->send($view, compact('token', 'user'), function($m) use ($user, $token, $callback) { $m->to($user->getReminderEmail()); - if ( ! is_null($callback)) call_user_func($callback, $m, $user, $token); + if ($callback !== null) { + call_user_func($callback, $m, $user, $token); + } }); } @@ -153,10 +155,10 @@ public function sendReminder(RemindableInterface $user, $token, Closure $callbac * * @param array $credentials * @param \Closure $callback - * @return mixed - */ - public function reset(array $credentials, Closure $callback) - { + * @return RemindableInterface|string|int + */ + public function reset(array $credentials, Closure $callback): RemindableInterface|string|int + { // If the responses from the validate method is not a user instance, we will // assume that it is a redirect and simply return it from this method and // the user is properly redirected having an error message on the post. @@ -179,25 +181,26 @@ public function reset(array $credentials, Closure $callback) return self::PASSWORD_RESET; } - /** - * Validate a password reset for the given credentials. - * - * @param array $credentials - * @return \Illuminate\Auth\Reminders\RemindableInterface - */ - protected function validateReset(array $credentials) - { - if (is_null($user = $this->getUser($credentials))) + /** + * Validate a password reset for the given credentials. + * + * @param array $credentials + * @return RemindableInterface|int|string + */ + protected function validateReset(array $credentials): RemindableInterface|int|string + { + $user = $this->getUser($credentials); + if ($user === null) { return self::INVALID_USER; } - if ( ! $this->validNewPasswords($credentials)) + if (!$this->validNewPasswords($credentials)) { return self::INVALID_PASSWORD; } - if ( ! $this->reminders->exists($user, $credentials['token'])) + if (!$this->reminders->exists($user, $credentials['token'])) { return self::INVALID_TOKEN; } @@ -211,8 +214,8 @@ protected function validateReset(array $credentials) * @param \Closure $callback * @return void */ - public function validator(Closure $callback) - { + public function validator(Closure $callback): void + { $this->passwordValidator = $callback; } @@ -222,9 +225,9 @@ public function validator(Closure $callback) * @param array $credentials * @return bool */ - protected function validNewPasswords(array $credentials) - { - list($password, $confirm) = array($credentials['password'], $credentials['password_confirmation']); + protected function validNewPasswords(array $credentials): bool + { + list($password, $confirm) = [$credentials['password'], $credentials['password_confirmation']]; if (isset($this->passwordValidator)) { @@ -240,24 +243,23 @@ protected function validNewPasswords(array $credentials) * @param array $credentials * @return bool */ - protected function validatePasswordWithDefaults(array $credentials) - { + protected function validatePasswordWithDefaults(array $credentials): bool + { list($password, $confirm) = [$credentials['password'], $credentials['password_confirmation']]; return $password === $confirm && mb_strlen((string) $password) >= 6; } - /** - * Get the user for the given credentials. - * - * @param array $credentials - * @return \Illuminate\Auth\Reminders\RemindableInterface - * - * @throws \UnexpectedValueException - */ - public function getUser(array $credentials) - { - $credentials = array_except($credentials, array('token')); + /** + * Get the user for the given credentials. + * + * @param array $credentials + * @return RemindableInterface|null + * + */ + public function getUser(array $credentials): ?RemindableInterface + { + $credentials = array_except($credentials, ['token']); $user = $this->users->retrieveByCredentials($credentials); @@ -274,8 +276,8 @@ public function getUser(array $credentials) * * @return \Illuminate\Auth\Reminders\ReminderRepositoryInterface */ - protected function getRepository() - { + protected function getRepository(): ReminderRepositoryInterface + { return $this->reminders; }