Completed
Push — master ( 9d8165...e9b726 )
by Cesar
28s queued 13s
created

UserProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 10
c 1
b 1
f 0
dl 0
loc 50
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsClass() 0 3 1
A refreshUser() 0 11 3
A upgradePassword() 0 2 1
A loadUserByUsername() 0 6 1
1
<?php
2
3
namespace App\Security;
4
5
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
6
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
7
use Symfony\Component\Security\Core\User\UserInterface;
8
use Symfony\Component\Security\Core\User\UserProviderInterface;
9
10
/**
11
 * Class UserProvider
12
 * @package App\Security
13
 */
14
class UserProvider implements UserProviderInterface, PasswordUpgraderInterface
15
{
16
    /**
17
     * @param string $username
18
     *
19
     * @return User|UserInterface
20
     */
21
    public function loadUserByUsername(string $username)
22
    {
23
        $user = new User();
24
        $user->setEmail($username);
25
26
        return $user;
27
    }
28
29
    /**
30
     * Refreshes the user after being reloaded from the session.
31
     *
32
     * @param UserInterface $user
33
     *
34
     * @return UserInterface
35
     */
36
    public function refreshUser(UserInterface $user)
37
    {
38
        if (!$user instanceof User) {
39
            throw new UnsupportedUserException(sprintf('Invalid user class "%s".', get_class($user)));
40
        }
41
42
        if (empty($user->getUsername())) {
43
            throw new UnsupportedUserException('Unable to find user\'s Username');
44
        }
45
46
        return $user;
47
    }
48
49
    /**
50
     * @param string $class
51
     * @return bool
52
     */
53
    public function supportsClass(string $class)
54
    {
55
        return User::class === $class;
56
    }
57
58
    /**
59
     * @param UserInterface $user
60
     * @param string $newEncodedPassword
61
     */
62
    public function upgradePassword(UserInterface $user, string $newEncodedPassword): void
63
    {
64
        //Not needed since no password is present;
65
    }
66
}
67