Passed
Pull Request — master (#104)
by Matt
04:36
created

User::getPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Entity;
4
5
use App\Repository\UserRepository;
6
use Doctrine\ORM\Mapping as ORM;
7
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
8
use Symfony\Component\Security\Core\User\UserInterface;
9
10
/**
11
 * @ORM\Entity(repositoryClass=UserRepository::class)
12
 */
13
class User implements UserInterface, PasswordAuthenticatedUserInterface
14
{
15
    /**
16
     * @ORM\Id
17
     * @ORM\GeneratedValue
18
     * @ORM\Column(type="integer")
19
     */
20
    private $id;
21
22
    /**
23
     * @ORM\Column(type="string", length=180, unique=true)
24
     */
25
    private $username;
26
27
    /**
28
     * @ORM\Column(type="json")
29
     */
30
    private $roles = [];
31
32
    /**
33
     * @var string The hashed password
34
     * @ORM\Column(type="string")
35
     */
36
    private $password;
37
38
    public function getId(): ?int
39
    {
40
        return $this->id;
41
    }
42
43
    /**
44
     * @deprecated since Symfony 5.3
45
     */
46
    public function getUsername(): string
47
    {
48
        return (string) $this->username;
49
    }
50
51
    /**
52
     * The public representation of the user (e.g. a username, an email address, etc.)
53
     *
54
     * @see UserInterface
55
     */
56
    public function getUserIdentifier(): string
57
    {
58
        return (string) $this->username;
59
    }
60
61
    public function setUsername(string $username): self
62
    {
63
        $this->username = $username;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @see UserInterface
70
     */
71
    public function getRoles(): array
72
    {
73
        $roles = $this->roles;
74
        // guarantee every user at least has ROLE_USER
75
        $roles[] = 'ROLE_USER';
76
77
        return array_unique($roles);
78
    }
79
80
    public function setRoles(array $roles): self
81
    {
82
        $this->roles = $roles;
83
84
        return $this;
85
    }
86
87
    /**
88
     * @see UserInterface
89
     */
90
    public function getPassword(): string
91
    {
92
        return (string) $this->password;
93
    }
94
95
    public function setPassword(string $password): self
96
    {
97
        $this->password = $password;
98
99
        return $this;
100
    }
101
102
    /**
103
     * @see UserInterface
104
     */
105
    public function getSalt()
106
    {
107
        // not needed when using the "bcrypt" algorithm in security.yaml
108
    }
109
110
    /**
111
     * @see UserInterface
112
     */
113
    public function eraseCredentials()
114
    {
115
        // If you store any temporary, sensitive data on the user, clear it here
116
        // $this->plainPassword = null;
117
    }
118
}
119