Passed
Push — main ( 06cd81...bfbca3 )
by Karl
19:32 queued 13:14
created

User::setPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
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
#[ORM\Entity(repositoryClass: UserRepository::class)]
11
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
12
class User implements UserInterface, PasswordAuthenticatedUserInterface
13
{
14
    #[ORM\Id]
15
    #[ORM\GeneratedValue]
16
    #[ORM\Column]
17
    private ?int $id = null;
18
19
    #[ORM\Column(length: 180)]
20
    private ?string $email = null;
21
22
    /**
23
     * @var list<string> The user roles
0 ignored issues
show
Bug introduced by
The type App\Entity\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
     */
25
    #[ORM\Column]
26
    private array $roles = [];
27
28
    /**
29
     * @var string The hashed password
30
     */
31
    #[ORM\Column]
32
    private ?string $password = null;
33
34
    public function getId(): ?int
35
    {
36
        return $this->id;
37
    }
38
39
    public function getEmail(): ?string
40
    {
41
        return $this->email;
42
    }
43
44
    public function setEmail(string $email): static
45
    {
46
        $this->email = $email;
47
48
        return $this;
49
    }
50
51
    /**
52
     * A visual identifier that represents this user.
53
     *
54
     * @see UserInterface
55
     */
56
    public function getUserIdentifier(): string
57
    {
58
        return (string) $this->email;
59
    }
60
61
    /**
62
     * @see UserInterface
63
     *
64
     * @return list<string>
65
     */
66
    public function getRoles(): array
67
    {
68
        $roles = $this->roles;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->roles of type array is incompatible with the declared type App\Entity\list of property $roles.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
69
        // guarantee every user at least has ROLE_USER
70
        $roles[] = 'ROLE_USER';
71
72
        return array_unique($roles);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_unique($roles) returns the type array which is incompatible with the documented return type App\Entity\list.
Loading history...
73
    }
74
75
    /**
76
     * @param list<string> $roles
77
     */
78
    public function setRoles(array $roles): static
79
    {
80
        $this->roles = $roles;
0 ignored issues
show
Documentation Bug introduced by
It seems like $roles of type array is incompatible with the declared type App\Entity\list of property $roles.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
81
82
        return $this;
83
    }
84
85
    /**
86
     * @see PasswordAuthenticatedUserInterface
87
     */
88
    public function getPassword(): string
89
    {
90
        return $this->password;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->password could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
91
    }
92
93
    public function setPassword(string $password): static
94
    {
95
        $this->password = $password;
96
97
        return $this;
98
    }
99
100
    /**
101
     * @see UserInterface
102
     */
103
    public function eraseCredentials(): void
104
    {
105
        // If you store any temporary, sensitive data on the user, clear it here
106
        // $this->plainPassword = null;
107
    }
108
}
109