Completed
Pull Request — dev (#24)
by
unknown
06:15
created

User::unserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
cc 1
eloc 7
nc 1
nop 1
crap 2
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Symfony\Component\Security\Core\User\UserInterface;
7
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Symfony\Component\Serializer\Annotation\Groups;
10
use Symfony\Component\Validator\Constraints as Assert;
11
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
12
13
/**
14
 * User.
15
 *
16
 * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
17
 * @UniqueEntity("email")
18
 */
19
class User implements UserInterface, \Serializable
20
{
21
    use ORMBehaviors\Timestampable\Timestampable;
22
    /**
23
     * @var int
24
     *
25
     * @ORM\Column(type="integer")
26
     * @ORM\Id
27
     * @ORM\GeneratedValue(strategy="AUTO")
28
     * @Groups({"Short"})
29
     */
30
    private $id;
31
32
    /**
33
     * @var string
34
     * @Assert\NotBlank()
35
     * @Assert\Regex(
36
     *     pattern="/\d/",
37
     *     match=false,
38
     *     message="Your name cannot contain a number"
39
     * )
40
     * @Assert\Type("string")
41
     * @Assert\Length(
42
     *      min = 2,
43
     *      max = 190
44
     * )
45
     * @ORM\Column(type="string", length=190)
46
     * @Groups({"Short"})
47
     */
48
    private $firstName;
49
50
    /**
51
     * @var string
52
     * @Assert\NotBlank()
53
     * @Assert\Regex(
54
     *     pattern="/\d/",
55
     *     match=false,
56
     *     message="Your lastname cannot contain a number"
57
     * )
58
     * @Assert\Type("string")
59
     * @Assert\Length(
60
     *      max = 190
61
     * )
62
     * @ORM\Column(type="string", length=190, nullable=true)
63
     * @Groups({"Short"})
64
     */
65
    private $lastName;
66
67
    /**
68
     * @var string
69
     * @Assert\Image()
70
     * @ORM\Column(type="string", nullable=true)
71
     */
72
    private $image;
73
74
    /**
75
     * @var string
76
     * @Assert\NotBlank()
77
     * @Assert\Email(
78
     * )
79
     * @Assert\Type("string")
80
     * @Assert\Length(
81
     *      max = 250
82
     * )
83
     * @ORM\Column(type="string", length=250, unique=true)
84
     * @Groups({"Short"})
85
     */
86
    private $email;
87
88
    /**
89
     * @var string
90
     * @ORM\Column(type="string", length=255)
91
     */
92
    private $password;
93
94
    /**
95
     * @var string
96
     * @Assert\Type("string")
97
     * @Assert\Length(
98
     *      max = 255
99
     * )
100
     * @Assert\NotBlank(groups={"registration"})
101
     */
102
    private $plainPassword;
103
104
    /**
105
     * @var bool
106
     * @ORM\Column(type="boolean")
107
     * @Groups({"Short"})
108
     */
109
    private $enabled = true;
110
111
    /**
112
     * @var
113
     * @ORM\Column(type="json_array")
114
     */
115
    protected $roles;
116
117
    /**
118
     * @var string
119
     *
120
     * @ORM\Column(type="string", unique=true, nullable=true)
121
     */
122
    private $apiToken;
123
124
    /**
125
     * @var ArrayCollection[Event]
126
     * @ORM\ManyToMany(targetEntity="Event", inversedBy="users", cascade={"persist", "remove"})
127
     */
128
    private $events;
129
130
    /**
131
     * @var ArrayCollection[FormRequest]
132
     * @ORM\OneToMany(targetEntity="FormRequest", mappedBy="user")
133
     */
134
    private $formRequests;
135
136
    /**
137
     * @var ArrayCollection[Survey]
138
     * @ORM\OneToMany(targetEntity="Survey", mappedBy="user")
139
     */
140
    private $surveys;
141
142 1
    public function __construct()
143
    {
144 1
        $this->events = new ArrayCollection();
145 1
        $this->formRequests = new ArrayCollection();
146 1
        $this->surveys = new ArrayCollection();
147 1
        $this->roles = array('ROLE_USER');
148 1
    }
149
150
    /**
151
     * Get id.
152
     *
153
     * @return int
154
     */
155 4
    public function getId()
156
    {
157 4
        return $this->id;
158
    }
159
160
    /**
161
     * Get name.
162
     *
163
     * @return string
164
     */
165 4
    public function getUsername()
166
    {
167 4
        return $this->email;
168
    }
169
170
    /**
171
     * Set firstname.
172
     *
173
     * @param string $name
174
     *
175
     * @return User
176
     */
177 2
    public function setFirstName($name)
178
    {
179 2
        $this->firstName = $name;
180
181 2
        return $this;
182
    }
183
184
    /**
185
     * Get first name.
186
     *
187
     * @return string
188
     */
189 9
    public function getFirstName()
190
    {
191 9
        return $this->firstName;
192
    }
193
194
    /**
195
     * Set lastName.
196
     *
197
     * @param string $lastName
198
     *
199
     * @return User
200
     */
201 2
    public function setLastName($lastName)
202
    {
203 2
        $this->lastName = $lastName;
204
205 2
        return $this;
206
    }
207
208
    /**
209
     * Get lastName.
210
     *
211
     * @return string
212
     */
213 8
    public function getLastName()
214
    {
215 8
        return $this->lastName;
216
    }
217
218
    /**
219
     * Set image.
220
     *
221
     * @param string $image
222
     *
223
     * @return User
224
     */
225
    public function setImage($image)
226
    {
227
        $this->image = $image;
228
229
        return $this;
230
    }
231
232
    /**
233
     * Get image.
234
     *
235
     * @return string
236
     */
237 1
    public function getImage()
238
    {
239 1
        return $this->image;
240
    }
241
242
    /**
243
     * Set email.
244
     *
245
     * @param string $email
246
     *
247
     * @return User
248
     */
249 2
    public function setEmail($email)
250
    {
251 2
        $this->email = $email;
252
253 2
        return $this;
254
    }
255
256
    /**
257
     * Get email.
258
     *
259
     * @return string
260
     */
261 5
    public function getEmail()
262
    {
263 5
        return $this->email;
264
    }
265
266
    /**
267
     * Set password.
268
     *
269
     * @param string $password
270
     *
271
     * @return User
272
     */
273 2
    public function setPassword($password)
274
    {
275 2
        $this->password = $password;
276
277 2
        return $this;
278
    }
279
280
    /**
281
     * Get password.
282
     *
283
     * @return string
284
     */
285 1
    public function getPassword()
286
    {
287 1
        return $this->password;
288
    }
289
290
    /**
291
     * @return string
292
     */
293 4
    public function getPlainPassword()
294
    {
295 4
        return $this->plainPassword;
296
    }
297
298
    /**
299
     * @param string $plainPassword
300
     */
301 6
    public function setPlainPassword($plainPassword)
302
    {
303 6
        $this->plainPassword = $plainPassword;
304 6
    }
305
306
    /**
307
     * @param mixed $roles
308
     */
309
    public function setRoles($roles)
310
    {
311
        $this->roles = $roles;
312
    }
313
314
    /**
315
     * @return mixed
316
     */
317 4
    public function getRoles()
318
    {
319 4
        return $this->roles;
320
    }
321
322
    /**
323
     * Set api token.
324
     *
325
     * @param string $apiToken
326
     *
327
     * @return User
328
     */
329 1
    public function setApiToken($apiToken)
330
    {
331 1
        $this->apiToken = $apiToken;
332
333 1
        return $this;
334
    }
335
336
    /**
337
     * @return string
338
     */
339
    public function getApiToken()
340
    {
341
        return $this->apiToken;
342
    }
343
344
    /**
345
     * @param Event $event
346
     *
347
     * @return User
348
     */
349
    public function setEvent($event)
350
    {
351
        if (!$this->events->contains($event)) {
352
            $this->events->add($event);
353
            $event->addUser($this);
354
        }
355
356
        return $this;
357
    }
358
359
    /**
360
     * @return ArrayCollection
361
     */
362
    public function getEvents()
363
    {
364
        return $this->events;
365
    }
366
367
    /**
368
     * @return ArrayCollection
369
     */
370
    public function getFormRequests()
371
    {
372
        return $this->formRequests;
373
    }
374
375
    /**
376
     * @return ArrayCollection
377
     */
378
    public function getSurveys()
379
    {
380
        return $this->surveys;
381
    }
382
383
    /**
384
     * Set enabled.
385
     *
386
     * @param bool $enabled
387
     *
388
     * @return User
389
     */
390 1
    public function setEnabled(bool $enabled)
391
    {
392 1
        $this->enabled = $enabled;
393
394 1
        return $this;
395
    }
396
397
    /**
398
     * Get enabled.
399
     *
400
     * @return bool
401
     */
402 4
    public function isEnabled()
403
    {
404 4
        return $this->enabled;
405
    }
406
407 2
    public function getSalt()
408
    {
409
        // TODO: Implement getSalt() method.
410 2
    }
411
412 4
    public function eraseCredentials()
413
    {
414 4
        $this->setPlainPassword(null);
415 4
    }
416
417
    /** @see \Serializable::serialize() */
418
    public function serialize()
419
    {
420
        return serialize(array(
421
            $this->id,
422
            $this->firstName,
423
            $this->lastName,
424
            $this->email,
425
            $this->enabled,
426
        ));
427
    }
428
429
    /** @see \Serializable::unserialize() */
430
    public function unserialize($serialized)
431
    {
432
        list(
433
            $this->id,
434
            $this->firstName,
435
            $this->lastName,
436
            $this->email,
437
            $this->enabled) = unserialize($serialized);
438
    }
439
}
440