Passed
Push — master ( e92978...ccd97d )
by Florian
01:54
created

User::setAmountPayed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the vseth-semesterly-reports project.
5
 *
6
 * (c) Florian Moser <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Entity;
13
14
use App\Entity\Base\BaseEntity;
15
use App\Entity\Traits\IdTrait;
16
use App\Enum\PaymentRemainderStatusType;
17
use App\Enum\UserCategoryType;
18
use App\Model\Bill\Recipient;
19
use App\Model\PaymentInfo;
20
use Doctrine\Common\Collections\ArrayCollection;
21
use Doctrine\ORM\Mapping as ORM;
22
use Ramsey\Uuid\Uuid;
23
24
/**
25
 * an event determines how the questionnaire looks like.
26
 *
27
 * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
28
 * @ORM\HasLifecycleCallbacks
29
 */
30
class User extends BaseEntity
31
{
32
    use IdTrait;
33
34
    /**
35
     * @var string
36
     *
37
     * @ORM\Column(type="text")
38
     */
39
    private $authenticationCode;
40
41
    /**
42
     * @var string
43
     *
44
     * @ORM\Column(type="text")
45
     */
46
    private $email;
47
48
    /**
49
     * @var string
50
     *
51
     * @ORM\Column(type="text")
52
     */
53
    private $givenName;
54
55
    /**
56
     * @var string
57
     *
58
     * @ORM\Column(type="text")
59
     */
60
    private $familyName;
61
62
    /**
63
     * @var string
64
     *
65
     * @ORM\Column(type="text")
66
     */
67
    private $address;
68
69
    /**
70
     * @var string
71
     *
72
     * @ORM\Column(type="text")
73
     */
74
    private $phone;
75
76
    /**
77
     * @var int
78
     *
79
     * @ORM\Column(type="integer")
80
     */
81
    private $category = UserCategoryType::STUDENT;
82
83
    /**
84
     * @var int
85
     *
86
     * @ORM\Column(type="integer")
87
     */
88
    private $discount = 0;
89
90
    /**
91
     * @var string|null
92
     *
93
     * @ORM\Column(type="text", nullable=true)
94
     */
95
    private $discountDescription;
96
97
    /**
98
     * @var \DateTime|null
99
     *
100
     * @ORM\Column(type="datetime", nullable=true)
101
     */
102
    private $lastPayedPeriodicFeeEnd;
103
104
    /**
105
     * @var int
106
     *
107
     * @ORM\Column(type="integer")
108
     */
109
    private $amountOwed;
110
111
    /**
112
     * @var int|null
113
     *
114
     * @ORM\Column(type="integer", nullable=true)
115
     */
116
    private $amountPayed;
117
118
    /**
119
     * @var string|null
120
     *
121
     * @ORM\Column(type="text", nullable=true)
122
     */
123
    private $transactionId;
124
125
    /**
126
     * @var string|null
127
     *
128
     * @ORM\Column(type="text", nullable=true)
129
     */
130
    private $invoiceId;
131
132
    /**
133
     * @var string|null
134
     *
135
     * @ORM\Column(type="text", nullable=true)
136
     */
137
    private $invoiceLink;
138
139
    /**
140
     * @var int
141
     *
142
     * @ORM\Column(type="integer")
143
     */
144
    private $paymentRemainderStatus = PaymentRemainderStatusType::NONE;
145
146
    /**
147
     * @var \DateTime|null
148
     *
149
     * @ORM\Column(type="datetime",nullable=true)
150
     */
151
    private $paymentRemainderStatusAt;
152
153
    /**
154
     * @var PaymentRemainder|null
155
     *
156
     * @ORM\ManyToOne(targetEntity="App\Entity\PaymentRemainder", inversedBy="users")
157
     */
158
    private $paymentRemainder;
159
160
    /**
161
     * @var Reservation[]|ArrayCollection
162
     *
163
     * @ORM\OneToMany(targetEntity="App\Entity\Reservation", mappedBy="user")
164
     */
165
    private $reservations;
166
167
    public function __construct()
168
    {
169
        $this->reservations = new ArrayCollection();
170
    }
171
172
    public function generateAuthenticationCode(): void
173
    {
174
        $this->authenticationCode = Uuid::uuid4();
0 ignored issues
show
Documentation Bug introduced by
It seems like Ramsey\Uuid\Uuid::uuid4() of type Ramsey\Uuid\UuidInterface is incompatible with the declared type string of property $authenticationCode.

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...
175
    }
176
177
    public function getEmail(): string
178
    {
179
        return $this->email;
180
    }
181
182
    public function setEmail(string $email): void
183
    {
184
        $this->email = $email;
185
    }
186
187
    public function getGivenName(): string
188
    {
189
        return $this->givenName;
190
    }
191
192
    public function setGivenName(string $givenName): void
193
    {
194
        $this->givenName = $givenName;
195
    }
196
197
    public function getFamilyName(): string
198
    {
199
        return $this->familyName;
200
    }
201
202
    public function setFamilyName(string $familyName): void
203
    {
204
        $this->familyName = $familyName;
205
    }
206
207
    public function getAddress(): string
208
    {
209
        return $this->address;
210
    }
211
212
    public function setAddress(string $address): void
213
    {
214
        $this->address = $address;
215
    }
216
217
    public function getPhone(): string
218
    {
219
        return $this->phone;
220
    }
221
222
    public function setPhone(string $phone): void
223
    {
224
        $this->phone = $phone;
225
    }
226
227
    public function getCategory(): int
228
    {
229
        return $this->category;
230
    }
231
232
    public function setCategory(int $category): void
233
    {
234
        $this->category = $category;
235
    }
236
237
    public function getDiscount(): int
238
    {
239
        return $this->discount;
240
    }
241
242
    public function setDiscount(int $discount): void
243
    {
244
        $this->discount = $discount;
245
    }
246
247
    public function getDiscountDescription(): ?string
248
    {
249
        return $this->discountDescription;
250
    }
251
252
    public function setDiscountDescription(?string $discountDescription): void
253
    {
254
        $this->discountDescription = $discountDescription;
255
    }
256
257
    public function getLastPayedPeriodicFeeEnd(): ?\DateTime
258
    {
259
        return $this->lastPayedPeriodicFeeEnd;
260
    }
261
262
    public function setLastPayedPeriodicFeeEnd(?\DateTime $lastPayedPeriodicFeeEnd): void
263
    {
264
        $this->lastPayedPeriodicFeeEnd = $lastPayedPeriodicFeeEnd;
265
    }
266
267
    public function getAmountOwed(): int
268
    {
269
        return $this->amountOwed;
270
    }
271
272
    public function setAmountOwed(int $amountOwed): void
273
    {
274
        $this->amountOwed = $amountOwed;
275
    }
276
277
    public function getInvoiceId(): ?string
278
    {
279
        return $this->invoiceId;
280
    }
281
282
    public function setInvoiceId(?string $invoiceId): void
283
    {
284
        $this->invoiceId = $invoiceId;
285
    }
286
287
    public function getInvoiceLink(): ?string
288
    {
289
        return $this->invoiceLink;
290
    }
291
292
    public function setInvoiceLink(?string $invoiceLink): void
293
    {
294
        $this->invoiceLink = $invoiceLink;
295
    }
296
297
    public function getPaymentRemainderStatus(): int
298
    {
299
        return $this->paymentRemainderStatus;
300
    }
301
302
    public function setPaymentRemainderStatus(int $paymentRemainderStatus): void
303
    {
304
        $this->paymentRemainderStatus = $paymentRemainderStatus;
305
        $this->paymentRemainderStatusAt = new \DateTime();
306
    }
307
308
    public function getPaymentRemainderStatusAt(): ?\DateTime
309
    {
310
        return $this->paymentRemainderStatusAt;
311
    }
312
313
    public function getPaymentRemainder(): ?PaymentRemainder
314
    {
315
        return $this->paymentRemainder;
316
    }
317
318
    public function setPaymentRemainder(?PaymentRemainder $paymentRemainder): void
319
    {
320
        $this->paymentRemainder = $paymentRemainder;
321
    }
322
323
    /**
324
     * @return Reservation[]|ArrayCollection
325
     */
326
    public function getReservations()
327
    {
328
        return $this->reservations;
329
    }
330
331
    public function writePaymentInfo(\App\Model\PaymentInfo $paymentInfo)
332
    {
333
        $this->invoiceId = $paymentInfo->getInvoiceId();
334
        $this->invoiceLink = $paymentInfo->getInvoiceLink();
335
    }
336
337
    /**
338
     * @return PaymentInfo
339
     */
340
    public function getPaymentInfo()
341
    {
342
        $paymentInfo = new PaymentInfo();
343
344
        $paymentInfo->setInvoiceId($this->invoiceId);
0 ignored issues
show
Bug introduced by
It seems like $this->invoiceId can also be of type null; however, parameter $invoiceId of App\Model\PaymentInfo::setInvoiceId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

344
        $paymentInfo->setInvoiceId(/** @scrutinizer ignore-type */ $this->invoiceId);
Loading history...
345
        $paymentInfo->setInvoiceLink($this->invoiceLink);
0 ignored issues
show
Bug introduced by
It seems like $this->invoiceLink can also be of type null; however, parameter $invoiceLink of App\Model\PaymentInfo::setInvoiceLink() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

345
        $paymentInfo->setInvoiceLink(/** @scrutinizer ignore-type */ $this->invoiceLink);
Loading history...
346
347
        return $paymentInfo;
348
    }
349
350
    public function clearPaymentInfo()
351
    {
352
        $this->invoiceLink = null;
353
        $this->invoiceId = null;
354
    }
355
356
    /**
357
     * @return Recipient
358
     */
359
    public function createRecipient()
360
    {
361
        $recipient = new Recipient();
362
        $recipient->setEmail($this->email);
363
364
        $recipient->setGivenName($this->givenName);
365
        $recipient->setFamilyName($this->familyName);
366
367
        $addressLines = explode("\n", $this->address);
368
        if (\count($addressLines) > 0) {
369
            $recipient->setStreet($addressLines[0]);
370
        }
371
372
        if (\count($addressLines) > 1) {
373
            $cityLine = $addressLines[\count($addressLines) - 1];
374
            $firstSpace = mb_strpos($cityLine, ' ');
375
            if ($firstSpace !== false) {
376
                $recipient->setPostcode(mb_substr($cityLine, 0, $firstSpace));
377
                $recipient->setPlace(mb_substr($cityLine, $firstSpace + 1));
378
            } else {
379
                $recipient->setPlace($cityLine);
380
            }
381
        }
382
383
        return $recipient;
384
    }
385
386
    public function getAuthenticationCode(): string
387
    {
388
        return $this->authenticationCode;
389
    }
390
391
    public function getAmountPayed(): ?int
392
    {
393
        return $this->amountPayed;
394
    }
395
396
    public function setAmountPayed(?int $amountPayed): void
397
    {
398
        $this->amountPayed = $amountPayed;
399
    }
400
401
    public function getTransactionId(): ?string
402
    {
403
        return $this->transactionId;
404
    }
405
406
    public function setTransactionId(?string $transactionId): void
407
    {
408
        $this->transactionId = $transactionId;
409
    }
410
}
411