Passed
Push — master ( 9d0dde...4d39d5 )
by Jan
08:02
created

User::getPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 *
5
 * part-db version 0.1
6
 * Copyright (C) 2005 Christoph Lechner
7
 * http://www.cl-projects.de/
8
 *
9
 * part-db version 0.2+
10
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
11
 * http://code.google.com/p/part-db/
12
 *
13
 * Part-DB Version 0.4+
14
 * Copyright (C) 2016 - 2019 Jan Böhmer
15
 * https://github.com/jbtronics
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
30
 *
31
 */
32
33
namespace App\Entity;
34
35
use App\Entity\Embeddables\PermissionEntity;
0 ignored issues
show
Bug introduced by
The type App\Entity\Embeddables\PermissionEntity 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...
36
use App\Security\Interfaces\HasPermissionsInterface;
37
use Doctrine\ORM\Mapping as ORM;
38
use Symfony\Component\Security\Core\User\UserInterface;
39
use Symfony\Component\Validator\Constraints as Assert;
40
41
/**
42
 * This entity represents a user, which can log in and have permissions.
43
 * Also this entity is able to save some informations about the user, like the names, email-address and other info.
44
 *
45
 * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
46
 * @ORM\Table("users")
47
 */
48
class User extends NamedDBElement implements UserInterface, HasPermissionsInterface
49
{
50
    /** The User id of the anonymous user */
51
    const ID_ANONYMOUS      = 1;
52
53
    /**
54
     * @ORM\Id()
55
     * @ORM\GeneratedValue()
56
     * @ORM\Column(type="integer")
57
     */
58
    protected $id;
59
60
    /**
61
     * @ORM\Column(type="string", length=180, unique=true)
62
     * @Assert\NotBlank
63
     */
64
    protected $name;
65
66
    /**
67
     * //@ORM\Column(type="json")
68
     */
69
    //protected $roles = [];
70
71
    /**
72
     * @var string|null The hashed password
73
     * @ORM\Column(type="string", nullable=true)
74
     */
75
    protected $password;
76
77
    /**
78
     * @var string|null The first name of the User
79
     * @ORM\Column(type="string", length=255, nullable=true)
80
     */
81
    protected $first_name = "";
82
83
    /**
84
     * @var string|null The last name of the User
85
     * @ORM\Column(type="string", length=255,  nullable=true)
86
     */
87
    protected $last_name = "";
88
89
    /**
90
     * @var string|null The department the user is working
91
     * @ORM\Column(type="string", length=255, nullable=true)
92
     */
93
    protected $department = "";
94
95
96
    /**
97
     * @var string|null The email address of the user
98
     * @ORM\Column(type="string", length=255, nullable=true)
99
     * @Assert\Email()
100
     */
101
    protected $email = "";
102
103
    /**
104
     * @var string|null The language/locale the user prefers
105
     * @ORM\Column(type="string", name="config_language", nullable=true)
106
     */
107
    protected $language = "";
108
109
    /**
110
     * @var string|null The timezone the user prefers
111
     * @ORM\Column(type="string", name="config_timezone", nullable=true)
112
     */
113
    protected $timezone = "";
114
115
    /**
116
     * @var string|null The theme
117
     * @ORM\Column(type="string", name="config_theme", nullable=true)
118
     */
119
    protected $theme = "";
120
121
    /**
122
     * @var Group|null The group this user belongs to.
123
     * @ORM\ManyToOne(targetEntity="Group", inversedBy="users", fetch="EAGER")
124
     * @ORM\JoinColumn(name="group_id", referencedColumnName="id")
125
     */
126
    protected $group;
127
128
    /** @var PermissionsEmbed
129
     * @ORM\Embedded(class="PermissionsEmbed", columnPrefix="perms_")
130
     */
131
    protected $permissions;
132
133
134
    /**
135
     * Checks if the current user, is the user which represents the not logged in (anonymous) users.
136
     * @return bool True if this user is the anonymous user.
137
     */
138
    public function isAnonymousUser() : bool
139
    {
140
        return $this->id === static::ID_ANONYMOUS && $this->name === 'anonymous';
141
    }
142
143
    /**
144
     * A visual identifier that represents this user.
145
     *
146
     * @see UserInterface
147
     */
148
    public function getUsername(): string
149
    {
150
        return (string) $this->name;
151
    }
152
153
    /**
154
     * @see UserInterface
155
     */
156
    public function getRoles(): array
157
    {
158
        $roles = [];
159
        //$roles = $this->roles;
160
        // guarantee every user at least has ROLE_USER
161
        $roles[] = 'ROLE_USER';
162
163
        return array_unique($roles);
164
    }
165
166
    public function setRoles(array $roles): self
0 ignored issues
show
Unused Code introduced by
The parameter $roles is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

166
    public function setRoles(/** @scrutinizer ignore-unused */ array $roles): self

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
167
    {
168
        //$this->roles = $roles;
169
170
        return $this;
171
    }
172
173
    /**
174
     * @see UserInterface
175
     * Gets the password hash for this entity.
176
     */
177
    public function getPassword(): string
178
    {
179
        return (string) $this->password;
180
    }
181
182
    /**
183
     * Sets the password hash for this user.
184
     * @param string $password
185
     * @return User
186
     */
187
    public function setPassword(string $password): self
188
    {
189
        $this->password = $password;
190
191
        return $this;
192
    }
193
194
    /**
195
     * @see UserInterface
196
     */
197
    public function getSalt()
198
    {
199
        // not needed when using the "bcrypt" algorithm in security.yaml
200
    }
201
202
    /**
203
     * @see UserInterface
204
     */
205
    public function eraseCredentials()
206
    {
207
        // If you store any temporary, sensitive data on the user, clear it here
208
        // $this->plainPassword = null;
209
    }
210
211
    /**
212
     * Returns the ID as an string, defined by the element class.
213
     * This should have a form like P000014, for a part with ID 14.
214
     * @return string The ID as a string;
215
     */
216
    public function getIDString(): string
217
    {
218
        return 'U' . sprintf('%06d', $this->getID());
219
    }
220
221
222
    public function getPermissions() : PermissionsEmbed
223
    {
224
        return $this->permissions;
225
    }
226
227
    /************************************************
228
     * Getters
229
     ************************************************/
230
231
    public function setName(string $new_name) : NamedDBElement
232
    {
233
        // Anonymous user is not allowed to change its username
234
        if(!$this->isAnonymousUser()) {
235
            $this->name = $new_name;
236
        }
237
238
        return $this;
239
    }
240
241
    /**
242
     * @return string
243
     */
244
    public function getFirstName(): ?string
245
    {
246
        return $this->first_name;
247
    }
248
249
    /**
250
     * @param string $first_name
251
     * @return User
252
     */
253
    public function setFirstName(?string $first_name): User
254
    {
255
        $this->first_name = $first_name;
256
        return $this;
257
    }
258
259
    /**
260
     * @return string
261
     */
262
    public function getLastName(): ?string
263
    {
264
        return $this->last_name;
265
    }
266
267
    /**
268
     * @param string $last_name
269
     * @return User
270
     */
271
    public function setLastName(?string $last_name): User
272
    {
273
        $this->last_name = $last_name;
274
        return $this;
275
    }
276
277
    /**
278
     * @return string
279
     */
280
    public function getDepartment(): ?string
281
    {
282
        return $this->department;
283
    }
284
285
    /**
286
     * @param string $department
287
     * @return User
288
     */
289
    public function setDepartment(?string $department): User
290
    {
291
        $this->department = $department;
292
        return $this;
293
    }
294
295
    /**
296
     * @return string
297
     */
298
    public function getEmail(): ?string
299
    {
300
        return $this->email;
301
    }
302
303
    /**
304
     * @param string $email
305
     * @return User
306
     */
307
    public function setEmail(?string $email): User
308
    {
309
        $this->email = $email;
310
        return $this;
311
    }
312
313
    /**
314
     * @return string
315
     */
316
    public function getLanguage(): ?string
317
    {
318
        return $this->language;
319
    }
320
321
    /**
322
     * @param string $language
323
     * @return User
324
     */
325
    public function setLanguage(?string $language): User
326
    {
327
        $this->language = $language;
328
        return $this;
329
    }
330
331
    /**
332
     * @return string
333
     */
334
    public function getTimezone(): ?string
335
    {
336
        return $this->timezone;
337
    }
338
339
    /**
340
     * @param string $timezone
341
     * @return User
342
     */
343
    public function setTimezone(?string $timezone): User
344
    {
345
        $this->timezone = $timezone;
346
        return $this;
347
    }
348
349
    /**
350
     * @return string
351
     */
352
    public function getTheme(): ?string
353
    {
354
        return $this->theme;
355
    }
356
357
    /**
358
     * @param string $theme
359
     * @return User
360
     */
361
    public function setTheme(?string $theme): User
362
    {
363
        $this->theme = $theme;
364
        return $this;
365
    }
366
367
    public function getGroup(): ?Group
368
    {
369
        return $this->group;
370
    }
371
372
    public function setGroup(?Group $group): self
373
    {
374
        $this->group = $group;
375
        return $this;
376
    }
377
378
}
379