Passed
Push — fix_coverage_in_scrutinizer ( cd0379...a04ba4 )
by Herberto
13:22
created

User::setUsername()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Entity;
13
14
use Doctrine\ORM\Mapping as ORM;
15
use Symfony\Component\Security\Core\User\UserInterface;
16
17
/**
18
 * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
19
 * @ORM\Table(name="symfony_demo_user")
20
 *
21
 * Defines the properties of the User entity to represent the application users.
22
 * See https://symfony.com/doc/current/book/doctrine.html#creating-an-entity-class
23
 *
24
 * Tip: if you have an existing database, you can generate these entity class automatically.
25
 * See https://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
26
 *
27
 * @author Ryan Weaver <[email protected]>
28
 * @author Javier Eguiluz <[email protected]>
29
 */
30
class User implements UserInterface, \Serializable
31
{
32
    /**
33
     * @var int
34
     *
35
     * @ORM\Id
36
     * @ORM\GeneratedValue
37
     * @ORM\Column(type="integer")
38
     */
39
    private $id;
40
41
    /**
42
     * @var string
43
     *
44
     * @ORM\Column(type="string")
45
     */
46
    private $fullName;
47
48
    /**
49
     * @var string
50
     *
51
     * @ORM\Column(type="string", unique=true)
52
     */
53
    private $username;
54
55
    /**
56
     * @var string
57
     *
58
     * @ORM\Column(type="string", unique=true)
59
     */
60
    private $email;
61
62
    /**
63
     * @var string
64
     *
65
     * @ORM\Column(type="string")
66
     */
67
    private $password;
68
69
    /**
70
     * @var array
71
     *
72
     * @ORM\Column(type="json")
73
     */
74
    private $roles = [];
75
76
    public function getId(): int
77
    {
78
        return $this->id;
79
    }
80
81 4
    public function setFullName(string $fullName): void
82
    {
83 4
        $this->fullName = $fullName;
84 4
    }
85
86 10
    public function getFullName(): string
87
    {
88 10
        return $this->fullName;
89
    }
90
91 8
    public function getUsername(): string
92
    {
93 8
        return $this->username;
94
    }
95
96 4
    public function setUsername(string $username): void
97
    {
98 4
        $this->username = $username;
99 4
    }
100
101 6
    public function getEmail(): string
102
    {
103 6
        return $this->email;
104
    }
105
106 4
    public function setEmail(string $email): void
107
    {
108 4
        $this->email = $email;
109 4
    }
110
111 14
    public function getPassword(): string
112
    {
113 14
        return $this->password;
114
    }
115
116 4
    public function setPassword(string $password): void
117
    {
118 4
        $this->password = $password;
119 4
    }
120
121
    /**
122
     * Returns the roles or permissions granted to the user for security.
123
     */
124 14
    public function getRoles(): array
125
    {
126 14
        $roles = $this->roles;
127
128
        // guarantees that a user always has at least one role for security
129 14
        if (empty($roles)) {
130 5
            $roles[] = 'ROLE_USER';
131
        }
132
133 14
        return array_unique($roles);
134
    }
135
136 4
    public function setRoles(array $roles): void
137
    {
138 4
        $this->roles = $roles;
139 4
    }
140
141
    /**
142
     * Returns the salt that was originally used to encode the password.
143
     *
144
     * {@inheritdoc}
145
     */
146 14
    public function getSalt(): ?string
147
    {
148
        // See "Do you need to use a Salt?" at https://symfony.com/doc/current/cookbook/security/entity_provider.html
149
        // we're using bcrypt in security.yml to encode the password, so
150
        // the salt value is built-in and you don't have to generate one
151
152 14
        return null;
153
    }
154
155
    /**
156
     * Removes sensitive data from the user.
157
     *
158
     * {@inheritdoc}
159
     */
160 10
    public function eraseCredentials(): void
161
    {
162
        // if you had a plainPassword property, you'd nullify it here
163
        // $this->plainPassword = null;
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
164 10
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169 10
    public function serialize(): string
170
    {
171 10
        return serialize([
172 10
            $this->id,
173 10
            $this->username,
174 10
            $this->password,
175
            // see section on salt below
176
            // $this->salt,
177
        ]);
178
    }
179
180
    /**
181
     * {@inheritdoc}
182
     */
183 4
    public function unserialize($serialized): void
184
    {
185
        list(
186 4
            $this->id,
187 4
            $this->username,
188 4
            $this->password,
189
            // see section on salt below
190
            // $this->salt
191 4
        ) = unserialize($serialized);
192 4
    }
193
}
194