The expression $token of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like ==, or !=, or switch conditions),
values of different types might be equal.
For string values, the empty string '' is a special case, in particular
the following results might be unexpected:
''==false// true''==null// true'ab'==false// false'ab'==null// false// It is often better to use strict comparison''===false// false''===null// false
Loading history...
25
$this->token = $token;
26
}
27
}
28
29
/**
30
* @return string
31
*/
32
public function getToken()
33
{
34
return $this->token;
35
}
36
37
/**
38
* Generates a token string.
39
*
40
* @return string
41
*/
42
private function generateToken()
43
{
44
return time() . base64_encode(random_bytes(10));
45
}
46
47
/**
48
* @param UserInterface $user
49
* @param $token
50
*
51
* @throws InvalidPasswordResetTokenException
52
*
53
* @return bool
54
*/
55
public static function validateToken(UserInterface $user, PasswordResetToken $token)
56
{
57
if ($user->getPasswordResetToken() === $token->getToken()) {
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: