User   A
last analyzed

Complexity

Total Complexity 28

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 6

Importance

Changes 0
Metric Value
wmc 28
lcom 3
cbo 6
dl 0
loc 159
rs 10
c 0
b 0
f 0

24 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getFirstName() 0 4 1
A setFirstName() 0 4 1
A getLastName() 0 4 1
A setLastName() 0 4 1
A getFullName() 0 4 1
A getUsername() 0 4 1
A setUsername() 0 4 1
A getEmail() 0 4 1
A setEmail() 0 4 1
A getSalt() 0 4 1
A getPassword() 0 4 1
A setPassword() 0 6 2
A getRoles() 0 4 1
A addRole() 0 4 1
A setRoles() 0 4 1
A eraseCredentials() 0 3 1
A serialize() 0 4 1
A unserialize() 0 4 1
A isEqualTo() 0 16 4
A getGroups() 0 4 1
A setGroups() 0 4 1
A getApiKey() 0 4 1
A setApiKey() 0 4 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\AppBundle\Entity;
14
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Doctrine\Common\Collections\Collection;
17
use Knp\DoctrineBehaviors\Model\Blameable\Blameable;
18
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable;
19
use Symfony\Component\Security\Core\User\EquatableInterface;
20
use Symfony\Component\Security\Core\User\UserInterface;
21
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Enableable;
22
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Identifiable;
23
use WellCommerce\Bundle\CoreBundle\Entity\EntityInterface;
24
25
/**
26
 * Class User
27
 *
28
 * @author  Adam Piotrowski <[email protected]>
29
 */
30
class User implements \Serializable, EquatableInterface, UserInterface, EntityInterface
31
{
32
    use Identifiable;
33
    use Enableable;
34
    use Timestampable;
35
    use Blameable;
36
    
37
    protected $firstName = '';
38
    protected $lastName  = '';
39
    protected $username  = '';
40
    protected $apiKey    = '';
41
    protected $password  = '';
42
    protected $email     = '';
43
    
44
    /**
45
     * @var Collection
46
     */
47
    protected $roles;
48
    
49
    /**
50
     * @var Collection
51
     */
52
    protected $groups;
53
    
54
    public function __construct()
55
    {
56
        $this->roles  = new ArrayCollection();
57
        $this->groups = new ArrayCollection();
58
        $this->apiKey = strtoupper(uniqid());
59
    }
60
    
61
    public function getFirstName(): string
62
    {
63
        return $this->firstName;
64
    }
65
    
66
    public function setFirstName(string $firstName)
67
    {
68
        $this->firstName = $firstName;
69
    }
70
    
71
    public function getLastName(): string
72
    {
73
        return $this->lastName;
74
    }
75
    
76
    public function setLastName(string $lastName)
77
    {
78
        $this->lastName = $lastName;
79
    }
80
    
81
    public function getFullName(): string
82
    {
83
        return sprintf('%s %s', $this->firstName, $this->lastName);
84
    }
85
    
86
    public function getUsername()
87
    {
88
        return $this->username;
89
    }
90
    
91
    public function setUsername($username)
92
    {
93
        $this->username = $username;
94
    }
95
    
96
    public function getEmail(): string
97
    {
98
        return $this->email;
99
    }
100
    
101
    public function setEmail(string $email)
102
    {
103
        $this->email = $email;
104
    }
105
    
106
    public function getSalt()
107
    {
108
        return null;
109
    }
110
    
111
    public function getPassword()
112
    {
113
        return $this->password;
114
    }
115
    
116
    public function setPassword($password)
117
    {
118
        if (strlen($password)) {
119
            $this->password = password_hash($password, PASSWORD_BCRYPT);
120
        }
121
    }
122
    
123
    public function getRoles()
124
    {
125
        return $this->roles->toArray();
126
    }
127
    
128
    public function addRole(Role $role)
129
    {
130
        $this->roles[] = $role;
131
    }
132
    
133
    public function setRoles(Collection $roles)
134
    {
135
        $this->roles = $roles;
136
    }
137
    
138
    public function eraseCredentials()
139
    {
140
    }
141
    
142
    public function serialize()
143
    {
144
        return serialize([$this->id, $this->username, $this->password]);
145
    }
146
    
147
    public function unserialize($serialized)
148
    {
149
        list($this->id, $this->username, $this->password) = unserialize($serialized);
150
    }
151
    
152
    public function isEqualTo(UserInterface $user)
153
    {
154
        if (!$user instanceof User) {
155
            return false;
156
        }
157
        
158
        if ($this->password !== $user->getPassword()) {
159
            return false;
160
        }
161
        
162
        if ($this->username !== $user->getUsername()) {
163
            return false;
164
        }
165
        
166
        return true;
167
    }
168
    
169
    public function getGroups(): Collection
170
    {
171
        return $this->groups;
172
    }
173
    
174
    public function setGroups(Collection $groups)
175
    {
176
        $this->groups = $groups;
177
    }
178
    
179
    public function getApiKey(): string
180
    {
181
        return $this->apiKey;
182
    }
183
    
184
    public function setApiKey(string $apiKey)
185
    {
186
        $this->apiKey = $apiKey;
187
    }
188
}
189