Completed
Push — master ( 4bb011...4b99be )
by Guillaume
13:23
created

User   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 3
dl 0
loc 134
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A createFromPayload() 0 7 1
A getRoles() 0 9 2
A setRoles() 0 10 3
A getPassword() 0 4 1
A setPassword() 0 4 1
A getSalt() 0 4 1
A getUsername() 0 4 1
A eraseCredentials() 0 3 1
A setEmail() 0 4 1
A getPlainPassword() 0 4 1
A setPlainPassword() 0 4 1
1
<?php
2
3
namespace Starkerxp\UserBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Lexik\Bundle\JWTAuthenticationBundle\Security\User\JWTUserInterface;
7
use Ramsey\Uuid\Uuid;
8
use Starkerxp\StructureBundle\Entity\Entity;
9
use Starkerxp\StructureBundle\Entity\UserInterface;
10
11
/**
12
 * User
13
 *
14
 * @ORM\Table(name="user", indexes={
15
 *  @ORM\Index(columns={"created_at"}),
16
 *  @ORM\Index(columns={"updated_at"})
17
 * })
18
 * @ORM\Entity(repositoryClass="Starkerxp\UserBundle\Repository\UserRepository")
19
 */
20
class User extends Entity implements JWTUserInterface, UserInterface
21
{
22
23
    /**
24
     * @var RoleUser
25
     *
26
     * @ORM\OneToOne(targetEntity="RoleUser", cascade={"persist"})
27
     * @ORM\JoinColumn(name="roles", referencedColumnName="id", nullable=true)
28
     */
29
    protected $roles;
30
31
    /**
32
     * @var string
33
     *
34
     * @ORM\Column(name="salt", type="string", length=255, nullable=true)
35
     */
36
    protected $salt;
37
38
    /**
39
     * @var string
40
     *
41
     * @ORM\Column(name="password", type="string", length=255)
42
     */
43
    protected $password;
44
    protected $plainPassword;
45
46
    /**
47
     * @var string
48
     *
49
     * @ORM\Column(name="email", type="string", length=255, nullable=false, unique=true)
50
     */
51
    protected $email;
52
53
    /**
54
     * User constructor.
55
     * @param array $roles
56
     * @param string $email
57
     */
58
    public function __construct($email, $roles)
59
    {
60
        $this->email = $email;
61
        $this->setRoles($roles);
62
        $uuid = Uuid::uuid4();
63
        $this->salt = $uuid->toString();
64
    }
65
66
    public static function createFromPayload($username, array $payload)
67
    {
68
        return new self(
69
            $username,
70
            $payload['roles']
71
        );
72
    }
73
74
    public function getRoles()
75
    {
76
        /** @var \Starkerxp\UserBundle\Entity\RoleUser $roles */
77
        if (empty($this->roles)) {
78
            return null;
79
        }
80
81
        return $this->roles->getRole();
82
    }
83
84
    /**
85
     * @param array $roles
86
     *
87
     * @return bool
88
     */
89
    public function setRoles($roles)
90
    {
91
        if($roles instanceof RoleUser || empty($this->roles) ){
0 ignored issues
show
Bug introduced by
The class Starkerxp\UserBundle\Entity\RoleUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
92
            $this->roles = new RoleUser($roles);
93
            return true;
94
        }
95
        $this->roles->setRoles($roles);
96
97
        return true;
98
    }
99
100
    public function getPassword()
101
    {
102
        return $this->password;
103
    }
104
105
    /**
106
     * @param string $password
107
     */
108
    public function setPassword($password)
109
    {
110
        $this->password = $password;
111
    }
112
113
    public function getSalt()
114
    {
115
        return $this->salt;
116
    }
117
118
    public function getUsername()
119
    {
120
        return $this->email;
121
    }
122
123
    public function eraseCredentials()
124
    {
125
    }
126
127
128
    /**
129
     * @param string $email
130
     */
131
    public function setEmail($email)
132
    {
133
        $this->email = $email;
134
    }
135
136
    /**
137
     * @return mixed
138
     */
139
    public function getPlainPassword()
140
    {
141
        return $this->plainPassword;
142
    }
143
144
    /**
145
     * @param mixed $plainPassword
146
     */
147
    public function setPlainPassword($plainPassword)
148
    {
149
        $this->plainPassword = $plainPassword;
150
    }
151
152
153
}
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...
154