User::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Model\User;
4
5
use Symfony\Component\Security\Core\User\UserInterface;
6
use App\Model\Organization;
7
use App\Model\Project\Project;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\Common\Collections\Collection;
10
11
abstract class User implements UserInterface, \JsonSerializable
12
{
13
    /** @var string **/
14
    protected $username;
15
    /** @var string **/
16
    protected $email;
17
    /** @var string **/
18
    protected $plainPassword;
19
    /** @var string **/
20
    protected $password;
21
    /** @var string **/
22
    protected $salt;
23
    /** @var ArrayCollection **/
24
    protected $roles;
25
    /** @var boolean **/
26
    protected $isEnabled;
27
    /** @var boolean **/
28
    protected $isLocked;
29
    /** @var ArrayCollection **/
30
    protected $organizations;
31
    /** @var ArrayCollction **/
0 ignored issues
show
Bug introduced by
The type App\Model\User\ArrayCollction 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...
32
    protected $projects;
33
    /** @var ActivationLink **/
34
    protected $activationLink;
35
    /** @var int **/
36
    protected $githubId;
37
    /** @var string **/
38
    protected $githubAccessToken;
39
    /** @var \DateTime **/
40
    protected $createdAt;
41
    /** @var \DateTime **/
42
    protected $updatedAt;
43
44
    const TYPE_MEMBER = 'ME';
45
    const TYPE_PRODUCT_OWNER = 'PO';
46
    const TYPE_BETA_TESTER = 'BT';
47
48
    abstract public function getType(): string;
49
50 25
    public function __construct()
51
    {
52 25
        $this->organizations = new ArrayCollection();
53 25
        $this->projects = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type App\Model\User\ArrayCollction of property $projects.

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...
54 25
        $this->roles = new ArrayCollection();
55 25
    }
56
57 17
    public function setUsername(string $username): User
58
    {
59 17
        $this->username = $username;
60
61 17
        return $this;
62
    }
63
64 13
    public function getUsername(): string
65
    {
66 13
        return $this->username;
67
    }
68
69 9
    public function setEmail(string $email): User
70
    {
71 9
        $this->email = $email;
72
73 9
        return $this;
74
    }
75
76 6
    public function getEmail(): string
77
    {
78 6
        return $this->email;
79
    }
80
81 4
    public function setPlainPassword(string $plainPassword): User
82
    {
83 4
        $this->plainPassword = $plainPassword;
84
85 4
        return $this;
86
    }
87
88 1
    public function getPlainPassword(): string
89
    {
90 1
        return $this->plainPassword;
91
    }
92
93 7
    public function setPassword(string$password):  User
94
    {
95 7
        $this->password = $password;
96
97 7
        return $this;
98
    }
99
100 10
    public function getPassword(): string
101
    {
102 10
        return $this->password;
103
    }
104
105 7
    public function setSalt(string $salt): User
106
    {
107 7
        $this->salt = $salt;
108
109 7
        return $this;
110
    }
111
112 13
    public function getSalt(): string
113
    {
114 13
        return $this->salt;
115
    }
116
117 8
    public function addRole(string $role): User
118
    {
119 8
        $this->roles->add($role);
120
121 8
        return $this;
122
    }
123
124 2
    public function hasRole(string $role): bool
125
    {
126 2
        return $this->roles->contains($role);
127
    }
128
129 1
    public function removeRole(string $role): User
130
    {
131 1
        if($this->hasRole($role)) {
132 1
            $this->roles->removeElement($role);
133
        }
134 1
        return $this;
135
    }
136
    
137 2
    public function setRoles(array $roles): User
138
    {
139 2
        $this->roles = new ArrayCollection($roles);
140
        
141 2
        return $this;
142
    }
143
144 13
    public function getRoles(): array
145
    {
146 13
        return $this->roles->toArray();
147
    }
148
149 10
    public function eraseCredentials(): bool
150
    {
151 10
        return true;
152
    }
153
154 14
    public function enable(bool $isEnabled): User
155
    {
156 14
        $this->isEnabled = $isEnabled;
157
158 14
        return $this;
159
    }
160
161 5
    public function isEnabled(): bool
162
    {
163 5
        return $this->isEnabled;
164
    }
165
166 7
    public function setIsLocked(bool $isLocked): User
167
    {
168 7
        $this->isLocked = $isLocked;
169
170 7
        return $this;
171
    }
172
173 1
    public function getIsLocked(): bool
174
    {
175 1
        return $this->isLocked;
176
    }
177
178 5
    public function addOrganization(Organization $organization): User
179
    {
180 5
        $this->organizations->add($organization);
181
182 5
        return $this;
183
    }
184
    
185
    public function removeOrganization(Organization $organization): User
186
    {
187
        $this->organizations->removeElement($organization);
188
        
189
        return $this;
190
    }
191
    
192 1
    public function hasOrganization(Organization $organization): bool
193
    {
194 1
        return $this->organizations->contains($organization);
195
    }
196
197 1
    public function getOrganizations(): ArrayCollection
198
    {
199 1
        return $this->organizations;
200
    }
201
    
202
    public function addProject(Project $project): User
203
    {
204
        $this->projects->add($project);
205
        
206
        return $this;
207
    }
208
    
209 2
    public function getProjects(): Collection
210
    {
211 2
        return $this->projects;
212
    }
213
214 9
    public function setActivationLink(ActivationLink $activationLink): User
215
    {
216 9
        $this->activationLink = $activationLink;
217
218 9
        return $this;
219
    }
220
221 6
    public function getActivationLink(): ?ActivationLink
222
    {
223 6
        return $this->activationLink;
224
    }
225
    
226
    public function setGithubId(int $githubId): User
227
    {
228
        $this->githubId = $githubId;
229
        
230
        return $this;
231
    }
232
    
233
    public function getGithubId(): ?int
234
    {
235
        return $this->githubId;
236
    }
237
    
238
    public function setGithubAccessToken(string $accessToken): User
239
    {
240
        $this->githubAccessToken = $accessToken;
241
        
242
        return $this;
243
    }
244
    
245
    public function getGithubAccessToken(): string
246
    {
247
        return $this->githubAccessToken;
248
    }
249
250 4
    public function setCreatedAt(\DateTime $createdAt): User
251
    {
252 4
        $this->createdAt = $createdAt;
253
254 4
        return $this;
255
    }
256
257 1
    public function getCreatedAt(): \DateTime
258
    {
259 1
        return $this->createdAt;
260
    }
261
262 4
    public function setUpdatedAt(\DateTime $updatedAt): User
263
    {
264 4
        $this->updatedAt = $updatedAt;
265
266 4
        return $this;
267
    }
268
269 1
    public function getUpdatedAt(): \DateTime
270
    {
271 1
        return $this->updatedAt;
272
    }
273
    
274 3
    public function jsonSerialize(): array
275
    {
276
        return  [
277 3
            'id' => $this->id,
278 3
            'username' => $this->username,
279 3
            'type' => $this->getType(),
280 3
            'organizations' => $this->organizations,
281 3
            'roles' => $this->roles,
282 3
            'is_enabled' => $this->isEnabled,
283 3
            'created_at' => $this->createdAt,
284 3
            'updated_at' => $this->updatedAt
285
        ];
286
    }
287
}