Completed
Push — master ( fac3e1...87ae16 )
by Guillaume
02:53
created

Utilisateur::getPlainPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Starkerxp\UtilisateurBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Lexik\Bundle\JWTAuthenticationBundle\Security\User\JWTUserInterface;
7
use Starkerxp\StructureBundle\Entity\Entity;
8
use Starkerxp\StructureBundle\Entity\UtilisateurInterface;
9
10
/**
11
 * Utilisateur
12
 *
13
 * @ORM\Table(name="utilisateur")
14
 * @ORM\Entity(repositoryClass="Starkerxp\UtilisateurBundle\Repository\UtilisateurRepository")
15
 */
16
class Utilisateur extends Entity implements JWTUserInterface, UtilisateurInterface
17
{
18
19
    /**
20
     * @var RoleUtilisateur
21
     *
22
     * @ORM\OneToOne(targetEntity="RoleUtilisateur", cascade={"persist"})
23
     * @ORM\JoinColumn(name="roles", referencedColumnName="id", nullable=true)
24
     */
25
    protected $roles;
26
27
    /**
28
     * @var string
29
     *
30
     * @ORM\Column(name="salt", type="string", length=255, nullable=true)
31
     */
32
    protected $salt;
33
34
    /**
35
     * @var string
36
     *
37
     * @ORM\Column(name="password", type="string", length=255)
38
     */
39
    protected $password;
40
    protected $plainPassword;
41
42
    /**
43
     * @var string
44
     *
45
     * @ORM\Column(name="email", type="string", length=255, nullable=false, unique=true)
46
     */
47
    protected $email;
48
49
    /**
50
     * Utilisateur constructor.
51
     * @param array $roles
52
     * @param string $email
53
     */
54
    public function __construct($email, $roles)
55
    {
56
        $this->email = $email;
57
        $this->setRoles($roles);
58
    }
59
60
    public static function createFromPayload($username, array $payload)
61
    {
62
        return new self(
63
            $username,
64
            $payload['roles']
65
        );
66
    }
67
68
    public function getRoles()
69
    {
70
        /** @var \Starkerxp\UtilisateurBundle\Entity\RoleUtilisateur $roles */
71
        if (empty($this->roles)) {
72
            return null;
73
        }
74
75
        return $this->roles->getRoles();
76
    }
77
78
    /**
79
     * @param array $roles
80
     *
81
     * @return bool
82
     */
83
    public function setRoles(array $roles)
84
    {
85
        if (empty($this->roles)) {
86
            $this->roles = new RoleUtilisateur($roles);
87
88
            return true;
89
        }
90
        $this->roles->setRoles($roles);
91
92
        return true;
93
    }
94
95
    public function getPassword()
96
    {
97
        return $this->password;
98
    }
99
100
    /**
101
     * @param string $password
102
     */
103
    public function setPassword($password)
104
    {
105
        $this->password = $password;
106
    }
107
108
    public function getSalt()
109
    {
110
        return $this->salt;
111
    }
112
113
    public function getUsername()
114
    {
115
        return $this->email;
116
    }
117
118
    public function eraseCredentials()
119
    {
120
    }
121
122
123
    /**
124
     * @param string $email
125
     */
126
    public function setEmail($email)
127
    {
128
        $this->email = $email;
129
    }
130
131
    /**
132
     * @return mixed
133
     */
134
    public function getPlainPassword()
135
    {
136
        return $this->plainPassword;
137
    }
138
139
    /**
140
     * @param mixed $plainPassword
141
     */
142
    public function setPlainPassword($plainPassword)
143
    {
144
        $this->plainPassword = $plainPassword;
145
    }
146
147
148
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
149