Completed
Pull Request — master (#144)
by
unknown
13:51
created

User::addOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 9.4285
ccs 1
cts 1
cp 1
crap 1
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Symfony\Component\Security\Core\User\UserInterface;
8
use JMS\Serializer\Annotation\ExclusionPolicy;
9
use JMS\Serializer\Annotation\Expose;
10
use JMS\Serializer\Tests\Fixtures\Order;
11
use Symfony\Component\Validator\Constraints as Assert;
12
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
13
14
/**
15
 * @ORM\Table(name="users")
16
 * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
17
 *
18
 * @DoctrineAssert\UniqueEntity(
19
 *     fields="facebookId",
20
 *     message="facebookId already exists",
21
 *     groups={"uniqFacebookId"}
22
 * )
23
 * @DoctrineAssert\UniqueEntity(
24
 *     fields="apiKey",
25
 *     message="apikey already exists",
26
 *     groups={"uniqApikey"}
27
 * )
28
 *
29
 * @ExclusionPolicy("all")
30
 */
31
class User implements UserInterface
32
{
33
    /**
34
     * @var int
35
     *
36
     * @ORM\Column(name="id", type="integer")
37
     * @ORM\Id
38
     * @ORM\GeneratedValue(strategy="AUTO")
39
     */
40
    protected $id;
41
42
    /**
43
     * @var string
44
     *
45
     * @ORM\Column(name="first_name", type="string", length=100, nullable=true)
46
     *
47
     * @Assert\Regex(pattern="/\d/", match=false)
48
     * @Assert\Type("string")
49
     * @Assert\Length(min=2, max=100)
50
     * @Assert\NotBlank(
51
     *     message="not.blank"
52
     * )
53
     *
54
     * @Expose
55
     */
56
    protected $firstName;
57
58
    /**
59
     * @var string
60
     *
61
     * @ORM\Column(name="last_name", type="string", length=100, nullable=true)
62
     *
63
     * @Assert\Regex(pattern="/\d/", match=false)
64
     * @Assert\Type("string")
65
     * @Assert\Length(min=2, max=100)
66
     * @Assert\NotBlank(
67
     *     message="not.blank"
68
     * )
69
     *
70
     * @Expose
71
     */
72
    protected $lastName;
73
74
    /**
75
     * @var string
76
     *
77
     * @ORM\Column(name="email", type="string", length=100, nullable=true)
78
     *
79
     * @Assert\Email()
80
     * @Assert\Type("string")
81
     * @Assert\Length(max=100)
82
     * @Assert\NotBlank(
83
     *     message="not.blank"
84
     * )
85
     *
86
     * @Expose
87
     */
88
    protected $email;
89
90
    /**
91
     * @var string
92
     *
93
     * @ORM\Column(name="username", type="string", length=100)
94
     *
95
     * @Assert\Type("string")
96
     * @Assert\Length(max=100)
97
     */
98
    protected $username;
99
100
    /**
101
     * @var string
102
     *
103
     * @ORM\Column(name="api_key", type="string", length=255, nullable=true, unique=true)
104
     *
105
     * @Assert\Type("string")
106
     * @Assert\Length(max=255)
107
     */
108
    private $apiKey;
109
110
    /**
111
     * @var string
112
     *
113
     * @ORM\Column(name="facebook_id", type="string", length=255, nullable=true, unique=true)
114
     *
115
     * @Assert\Type("string")
116
     * @Assert\Length(max=255)
117
     */
118
    private $facebookId;
119
120
    /**
121
     * @var ArrayCollection|Order[]
122
     *
123
     * @ORM\OneToMany(
124
     *     targetEntity="AppBundle\Entity\UserOrder",
125
     *     mappedBy="user",
126
     *     cascade={"persist", "remove"},
127
     *     orphanRemoval=true
128
     * )
129
     */
130
    private $orders;
131
132
    /**
133
     * @var string
134
     *
135
     * @ORM\Column(name="role", type="string", length=50)
136
     */
137
    private $role;
138 30
139
    /**
140 30
     * @return int
141
     */
142 30
    public function getId(): int
143
    {
144
        return $this->id;
145
    }
146
147
    /**
148 7
     * @param string $apiKey
149
     *
150 7
     * @return User
151
     */
152
    public function setApiKey(?string $apiKey): User
153
    {
154
        $this->apiKey = $apiKey;
155
156
        return $this;
157
    }
158
159 30
    /**
160
     * @return string
161 30
     */
162
    public function getApiKey(): ?string
163 30
    {
164
        return $this->apiKey;
165
    }
166
167
    /**
168
     * Add order.
169
     *
170
     * @param UserOrder $order
171
     *
172
     * @return User
173
     */
174
    public function addOrder(UserOrder $order)
175
    {
176
        $this->orders[] = $order;
177
178
        return $this;
179 14
    }
180
181 14
    /**
182
     * Remove order.
183
     *
184
     * @param UserOrder $order
185
     */
186
    public function removeOrder(UserOrder $order)
187
    {
188
        $this->orders->removeElement($order);
189
    }
190
191
    /**
192
     * Get orders.
193
     *
194
     * @return \Doctrine\Common\Collections\Collection
195
     */
196
    public function getOrders()
197
    {
198
        return $this->orders;
199
    }
200
201 14
    /**
202
     * @param string $role
203 14
     *
204
     * @return User
205
     */
206
    public function setRole(?string $role): User
207
    {
208
        $this->role = $role;
209
210 15
        return $this;
211
    }
212 15
213
    /**
214 15
     * @return string
215
     */
216
    public function getRole(): ?string
217
    {
218
        return $this->role;
219
    }
220
221
222
223
    /**
224
     * @inheritdoc
225
     */
226
    public function getRoles()
227
    {
228
        return array($this->role);
229
    }
230 30
231
    /**
232 30
     * @inheritdoc
233
     */
234 30
    public function getPassword()
235
    {
236
    }
237
238
    /**
239
     * @inheritdoc
240 14
     */
241
    public function getSalt()
242 14
    {
243
    }
244
245
    /**
246
     * @inheritdoc
247
     */
248
    public function eraseCredentials()
249
    {
250 4
    }
251
252 4
    /**
253
     * @param string $facebookId
254 4
     *
255
     * @return User
256
     */
257
    public function setFacebookId(?string $facebookId): User
258
    {
259
        $this->facebookId = $facebookId;
260
261
        return $this;
262
    }
263
264
    /**
265
     * @return string
266
     */
267
    public function getFacebookId(): ?string
268
    {
269
        return $this->facebookId;
270 4
    }
271
272 4
    /**
273
     * @param string $username
274 4
     *
275
     * @return User
276
     */
277
    public function setUsername(?string $username): User
278
    {
279
        $this->username = $username;
280
281
        return $this;
282
    }
283
284
    /**
285
     * @return string
286
     */
287
    public function getUsername(): ?string
288
    {
289
        return $this->username;
290 4
    }
291
292 4
    /**
293
     * @param string $firstName
294 4
     *
295
     * @return User
296
     */
297
    public function setFirstName(?string $firstName): User
298
    {
299
        $this->firstName = $firstName;
300
301
        return $this;
302
    }
303
304
    /**
305
     * @return string
306
     */
307
    public function getFirstName(): ?string
308
    {
309
        return $this->firstName;
310
    }
311
312
    /**
313
     * @param string $lastName
314
     *
315
     * @return User
316
     */
317
    public function setLastName(?string $lastName): User
318
    {
319
        $this->lastName = $lastName;
320
321
        return $this;
322
    }
323
324
    /**
325
     * @return string
326
     */
327
    public function getLastName(): ?string
328
    {
329
        return $this->lastName;
330
    }
331
332
    /**
333
     * @param string $email
334
     *
335
     * @return User
336
     */
337
    public function setEmail(?string $email): User
338
    {
339
        $this->email = $email;
340
341
        return $this;
342
    }
343
344
    /**
345
     * @return string
346
     */
347
    public function getEmail(): ?string
348
    {
349
        return $this->email;
350
    }
351
}
352