Completed
Pull Request — master (#12)
by
unknown
02:46
created

PasswordResetToken::validateToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Security;
4
5
use SumoCoders\FrameworkMultiUserBundle\Exception\InvalidPasswordResetTokenException;
6
use SumoCoders\FrameworkMultiUserBundle\User\UserInterface;
7
8
class PasswordResetToken
9
{
10
    private static function generatePasswordResetToken()
11
    {
12
        return time() . base64_encode(random_bytes(10));
13
    }
14
15
    public static function validateToken(UserInterface $user, $token)
16
    {
17
        if ($user->getPasswordResetToken() === $token) {
0 ignored issues
show
Bug introduced by
The method getPasswordResetToken() does not exist on SumoCoders\FrameworkMult...ndle\User\UserInterface. Did you maybe mean getPassword()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
18
            return true;
19
        }
20
21
        throw new InvalidPasswordResetTokenException('The given token is not valid.');
22
    }
23
24
    public static function generate()
25
    {
26
        return self::generatePasswordResetToken();
27
    }
28
}
29