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

User::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 3
Metric Value
c 3
b 0
f 3
dl 0
loc 11
rs 9.4285
cc 2
eloc 7
nc 2
nop 5
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\User;
4
5
use SumoCoders\FrameworkMultiUserBundle\Security\PasswordResetToken;
6
7
class User implements UserInterface, PasswordReset
8
{
9
    /** @var string */
10
    private $username;
11
12
    /** @var string */
13
    private $password;
14
15
    /** @var string */
16
    private $displayName;
17
18
    /** @var */
19
    private $passwordResetToken;
20
21
    /** @var */
22
    private $email;
23
24
    /**
25
     * @param string $username
26
     * @param string $password
27
     * @param string $displayName
28
     * @param $email
29
     * @param PasswordResetToken $token
30
     */
31
    public function __construct($username, $password, $displayName, $email, PasswordResetToken $token = null)
32
    {
33
        $this->username = $username;
34
        $this->password = $password;
35
        $this->displayName = $displayName;
36
        $this->email = $email;
37
        
38
        if ($token) {
39
            $this->passwordResetToken = $token->getToken();
40
        }
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function getRoles()
47
    {
48
        return [ 'ROLE_USER' ];
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    public function getPassword()
55
    {
56
        return $this->password;
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function getSalt()
63
    {
64
        return;
65
    }
66
67
    /**
68
     * {@inheritDoc}
69
     */
70
    public function getUsername()
71
    {
72
        return $this->username;
73
    }
74
75
    /**
76
     * {@inheritDoc}
77
     */
78
    public function eraseCredentials()
79
    {
80
        return;
81
    }
82
83
    /**
84
     * {@inheritDoc}
85
     */
86
    public function getDisplayName()
87
    {
88
        return $this->displayName;
89
    }
90
91
    /**
92
     * {@inheritDoc}
93
     */
94
    public function __toString()
95
    {
96
        return $this->getDisplayName();
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function clearPasswordResetToken()
103
    {
104
        $this->passwordResetToken = null;
105
106
        return $this;
107
    }
108
109
    /**
110
     * @return self
111
     */
112
    public function generatePasswordResetToken()
113
    {
114
        $token = PasswordResetToken::generate();
115
        $this->passwordResetToken = $token->getToken();
116
117
        return $this;
118
    }
119
120
    /**
121
     * @return string
122
     */
123
    public function getPasswordResetToken()
124
    {
125
        return $this->passwordResetToken;
126
    }
127
128
    /**
129
     * @return string
130
     */
131
    public function getEmail()
132
    {
133
        return $this->email;
134
    }
135
136
    /**
137
     * @param $password
138
     *
139
     * @return self
140
     */
141
    public function setPassword($password)
142
    {
143
        $this->password = $password;
144
145
        return $this;
146
    }
147
}
148