/** * Set password. * * @param string $password * @param PasswordHasherInterface $passwordHasher * @param string|null $old * * @throws \InvalidArgumentException If the update fails. * * @return User */ public function setOrUpdatePassword(string $password, PasswordHasherInterface $passwordHasher, string $old = null) : self { if ($this->password && !$passwordHasher->compareWith($this->password, $old)) { throw new \InvalidArgumentException('Old password is invalid, but must be given to change it!'); } $this->password = $passwordHasher->generateHash($password); return $this; }