PhpDraftSecurityUser   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 17
eloc 34
dl 0
loc 88
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A getEmail() 0 2 1
A isAdmin() 0 2 1
A getName() 0 2 1
A eraseCredentials() 0 2 1
A getUsername() 0 3 1
A hasVerificationKey() 0 2 1
A getPassword() 0 3 1
A isEnabled() 0 2 1
A getRoles() 0 3 1
A verificationKeyMatches() 0 2 1
A getSalt() 0 3 1
A __construct() 0 9 1
A isEqualTo() 0 19 5
1
<?php
2
namespace PhpDraft\Config\Security;
3
4
use Symfony\Component\Security\Core\User\UserInterface;
5
use Symfony\Component\Security\Core\User\EquatableInterface;
6
use Symfony\Component\Security\Core\Util\StringUtils;
7
8
class PhpDraftSecurityUser implements UserInterface, EquatableInterface
9
{
10
    private $email;
11
    private $name;
12
    private $enabled;
13
    private $password;
14
    private $salt;
15
    private $roles;
16
    private $verificationKey;
17
18
    public function __construct($email, $name, $password, $salt, array $roles, $enabled, $verificationKey)
19
    {
20
        $this->email = $email;
21
        $this->name = $name;
22
        $this->password = $password;
23
        $this->salt = $salt;
24
        $this->roles = $roles;
25
        $this->enabled = $enabled;
26
        $this->verificationKey = $verificationKey;
27
    }
28
29
    public function getRoles()
30
    {
31
        return $this->roles;
32
    }
33
34
    public function getPassword()
35
    {
36
        return $this->password;
37
    }
38
39
    public function getSalt()
40
    {
41
        return $this->salt;
42
    }
43
44
    public function getUsername()
45
    {
46
        return $this->email;
47
    }
48
49
    public function getName() {
50
        return $this->name;
51
    }
52
53
    public function getEmail() {
54
        return $this->email;
55
    }
56
57
    public function eraseCredentials()
58
    {
59
    }
60
61
    public function isEnabled() {
62
        return $this->enabled;
63
    }
64
65
    public function isAdmin() {
66
        return in_array('ROLE_ADMIN', $this->roles);
67
    }
68
69
    public function hasVerificationKey() {
70
        return !empty($this->verificationKey);
71
    }
72
73
    public function verificationKeyMatches($provided_key) {
74
        return StringUtils::equals($this->verificationKey, $provided_key);
75
    }
76
77
    public function isEqualTo(UserInterface $user)
78
    {
79
        if (!$user instanceof PhpDraftSecurityUser) {
80
            return false;
81
        }
82
83
        if ($this->password !== $user->getPassword()) {
84
            return false;
85
        }
86
87
        if ($this->salt !== $user->getSalt()) {
88
            return false;
89
        }
90
91
        if ($this->email !== $user->getUsername()) {
92
            return false;
93
        }
94
95
        return true;
96
    }
97
}