Passed
Push — master ( a34e41...faa861 )
by Will
04:01
created

AlmaUser::isEqualTo()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Security\User;
4
5
use Symfony\Component\Security\Core\User\EquatableInterface;
6
use Symfony\Component\Security\Core\User\UserInterface;
7
8
class AlmaUser implements UserInterface, EquatableInterface
9
{
10
    private $username;
11
    private $roles;
12
    private $firstName;
13
    private $lastName;
14
15
    public function __construct($username, array $roles, $firstName, $lastName)
16
    {
17
        $this->username = $username;
18
        $this->roles = $roles;
19
        $this->firstName = $firstName;
20
        $this->lastName = $lastName;
21
    }
22
23
    /**
24
     * Returns the roles granted to the user.
25
     *
26
     * <code>
27
     * public function getRoles()
28
     * {
29
     *     return array('ROLE_USER');
30
     * }
31
     * </code>
32
     *
33
     * Alternatively, the roles might be stored on a ``roles`` property,
34
     * and populated in any number of different ways when the user object
35
     * is created.
36
     *
37
     * @return array (Role|string)[] The user roles
38
     */
39
    public function getRoles()
40
    {
41
        return $this->roles;
42
    }
43
44
    /**
45
     * Returns the password used to authenticate the user.
46
     *
47
     * This should be the encoded password. On authentication, a plain-text
48
     * password will be salted, encoded, and then compared to this value.
49
     *
50
     * @return string The password
51
     */
52
    public function getPassword()
53
    {
54
        return null;
55
    }
56
57
    /**
58
     * Returns the salt that was originally used to encode the password.
59
     *
60
     * This can return null if the password was not encoded using a salt.
61
     *
62
     * @return string|null The salt
63
     */
64
    public function getSalt()
65
    {
66
        return null;
67
    }
68
69
    /**
70
     * Returns the username used to authenticate the user.
71
     *
72
     * @return string The username
73
     */
74
    public function getUsername()
75
    {
76
        return $this->username;
77
    }
78
79
    /**
80
     * Removes sensitive data from the user.
81
     *
82
     * This is important if, at any given point, sensitive information like
83
     * the plain-text password is stored on this object.
84
     */
85
    public function eraseCredentials()
86
    {
87
    }
88
89
    /**
90
     * The equality comparison should neither be done by referential equality
91
     * nor by comparing identities (i.e. getId() === getId()).
92
     *
93
     * However, you do not need to compare every attribute, but only those that
94
     * are relevant for assessing whether re-authentication is required.
95
     *
96
     * Also implementation should consider that $user instance may implement
97
     * the extended user interface `AdvancedUserInterface`.
98
     *
99
     * @param UserInterface $user
100
     * @return bool
101
     */
102
    public function isEqualTo(UserInterface $user)
103
    {
104
        if (!$user instanceof AlmaUser) {
105
            return false;
106
        }
107
        if ($this->username !== $user->getUsername()) {
108
            return false;
109
        }
110
        return true;
111
    }
112
113
    /**
114
     * @return string
115
     */
116
    public function getFirstName()
117
    {
118
        return $this->firstName;
119
    }
120
121
    /**
122
     * @return string
123
     */
124
    public function getLastName()
125
    {
126
        return $this->lastName;
127
    }
128
}
129