Completed
Pull Request — master (#12)
by
unknown
03:10
created

PasswordResetToken   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 3
c 3
b 1
f 1
lcom 0
cbo 1
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateToken() 0 8 2
A generate() 0 4 1
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
    /**
11
     * @param UserInterface $user
12
     * @param $token
13
     *
14
     * @return bool
15
     *
16
     * @throws InvalidPasswordResetTokenException
17
     */
18
    public static function validateToken(UserInterface $user, $token)
19
    {
20
        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...
21
            return true;
22
        }
23
24
        throw new InvalidPasswordResetTokenException('The given token is not valid.');
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public static function generate()
31
    {
32
        return time() . base64_encode(random_bytes(10));
33
    }
34
}
35