Failed Conditions
Push — master ( b2f91e...4de03e )
by Sam
08:24
created

Bookable::setPeriodicPrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\DBAL\Types\BookableStateType;
8
use Application\DBAL\Types\BookingTypeType;
9
use Application\Traits\HasCode;
10
use Application\Traits\HasDescription;
11
use Application\Traits\HasName;
12
use Application\Traits\HasRemarks;
13
use Cake\Chronos\Date;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Doctrine\ORM\Mapping as ORM;
17
use GraphQL\Doctrine\Annotation as API;
18
19
/**
20
 * An item that can be booked by a user
21
 *
22
 * @ORM\Entity(repositoryClass="Application\Repository\BookableRepository")
23
 */
24
class Bookable extends AbstractModel
25
{
26
    use HasName;
27
    use HasDescription;
28
    use HasCode;
29
    use HasRemarks;
30
31
    /**
32
     * @var string
33
     *
34
     * @ORM\Column(type="decimal", precision=7, scale=2, options={"default" = "0.00"})
35
     */
36
    private $initialPrice = '0';
37
38
    /**
39
     * @var string
40
     *
41
     * @ORM\Column(type="decimal", precision=7, scale=2, options={"default" = "0.00"})
42
     */
43
    private $periodicPrice = '0';
44
45
    /**
46
     * @var int
47
     *
48
     * @ORM\Column(type="smallint", options={"unsigned" = true, "default" = "1"})
49
     */
50
    private $simultaneousBookingMaximum = 1;
51
52
    /**
53
     * @var string
54
     *
55
     * @ORM\Column(type="BookingType", length=10, options={"default" = BookingTypeType::SELF_APPROVED})
56
     */
57
    private $bookingType = BookingTypeType::SELF_APPROVED;
58
59
    /**
60
     * @var bool
61
     *
62
     * @ORM\Column(type="boolean", options={"default" = 1})
63
     */
64
    private $isActive = true;
65
66
    /**
67
     * @var string
68
     *
69
     * @ORM\Column(type="BookableState", length=10, options={"default" = BookableStateType::GOOD})
70
     */
71
    private $state = BookableStateType::GOOD;
72
73
    /**
74
     * @var null|Date
75
     * @ORM\Column(type="date", nullable=true)
76
     */
77
    private $verificationDate;
78
79
    /**
80
     * @var BookableTag
81
     *
82
     * @ORM\ManyToMany(targetEntity="BookableTag", mappedBy="bookables")
83
     */
84
    private $bookableTags;
85
86
    /**
87
     * @var Collection
88
     * @ORM\ManyToMany(targetEntity="Booking", mappedBy="bookables")
89
     */
90
    private $bookings;
91
92
    /**
93
     * @var Collection
94
     * @ORM\OneToMany(targetEntity="Transaction", mappedBy="bookable")
95
     */
96
    private $transactions;
97
98
    /**
99
     * @var Collection
100
     * @ORM\ManyToMany(targetEntity="License", mappedBy="bookables")
101
     */
102
    private $licenses;
103
104
    /**
105
     * @var null|Image
106
     * @ORM\OneToOne(targetEntity="Image", orphanRemoval=true)
107
     * @ORM\JoinColumn(name="image_id", referencedColumnName="id")
108
     */
109
    private $image;
110
111
    /**
112
     * Constructor
113
     */
114 6
    public function __construct()
115
    {
116 6
        $this->bookings = new ArrayCollection();
117 6
        $this->licenses = new ArrayCollection();
118 6
        $this->bookableTags = 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 Application\Model\BookableTag of property $bookableTags.

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...
119 6
        $this->transactions = new ArrayCollection();
120 6
    }
121
122
    /**
123
     * @return Collection
124
     */
125 1
    public function getBookings(): Collection
126
    {
127 1
        return $this->bookings;
128
    }
129
130
    /**
131
     * Notify the bookable that it has a new booking.
132
     * This should only be called by Booking::addBookable()
133
     *
134
     * @param Booking $booking
135
     */
136 1
    public function bookingAdded(Booking $booking): void
137
    {
138 1
        $this->bookings->add($booking);
139 1
    }
140
141
    /**
142
     * Notify the bookable that it a booking was removed.
143
     * This should only be called by Booking::removeBookable()
144
     *
145
     * @param Booking $booking
146
     */
147 1
    public function bookingRemoved(Booking $booking): void
148
    {
149 1
        $this->bookings->removeElement($booking);
150 1
    }
151
152
    /**
153
     * @return Collection
154
     */
155 1
    public function getLicenses(): Collection
156
    {
157 1
        return $this->licenses;
158
    }
159
160
    /**
161
     * Notify the bookable that it has a new license.
162
     * This should only be called by License::addBookable()
163
     *
164
     * @param License $license
165
     */
166 1
    public function licenseAdded(License $license): void
167
    {
168 1
        $this->licenses->add($license);
169 1
    }
170
171
    /**
172
     * Notify the bookable that it a license was removed.
173
     * This should only be called by License::removeBookable()
174
     *
175
     * @param License $license
176
     */
177 1
    public function licenseRemoved(License $license): void
178
    {
179 1
        $this->licenses->removeElement($license);
180 1
    }
181
182
    /**
183
     * @return string
184
     */
185
    public function getInitialPrice(): string
186
    {
187
        return $this->initialPrice;
188
    }
189
190
    /**
191
     * @param string $initialPrice
192
     */
193
    public function setInitialPrice(string $initialPrice): void
194
    {
195
        $this->initialPrice = $initialPrice;
196
    }
197
198
    /**
199
     * @return string
200
     */
201
    public function getPeriodicPrice(): string
202
    {
203
        return $this->periodicPrice;
204
    }
205
206
    /**
207
     * @param string $periodicPrice
208
     */
209
    public function setPeriodicPrice(string $periodicPrice): void
210
    {
211
        $this->periodicPrice = $periodicPrice;
212
    }
213
214
    /**
215
     * @return int
216
     */
217
    public function getSimultaneousBookingMaximum(): int
218
    {
219
        return $this->simultaneousBookingMaximum;
220
    }
221
222
    /**
223
     * @param int $simultaneousBookingMaximum
224
     */
225
    public function setSimultaneousBookingMaximum(int $simultaneousBookingMaximum): void
226
    {
227
        $this->simultaneousBookingMaximum = $simultaneousBookingMaximum;
228
    }
229
230
    /**
231
     * @API\Field(type="BookingType")
232
     *
233
     * @return string
234
     */
235
    public function getBookingType(): string
236
    {
237
        return $this->bookingType;
238
    }
239
240
    /**
241
     * Whether this bookable can be booked
242
     *
243
     * @return bool
244
     */
245
    public function isActive(): bool
246
    {
247
        return $this->isActive;
248
    }
249
250
    /**
251
     * Whether this bookable can be booked
252
     *
253
     * @param bool $isActive
254
     */
255
    public function setIsActive(bool $isActive): void
256
    {
257
        $this->isActive = $isActive;
258
    }
259
260
    /**
261
     * @API\Input(type="BookingType")
262
     *
263
     * @param string $state
264
     */
265
    public function setBookingType(string $state): void
266
    {
267
        $this->bookingType = $state;
268
    }
269
270
    /**
271
     * State of the bookable
272
     *
273
     * @API\Field(type="BookableState")
274
     *
275
     * @return string
276
     */
277
    public function getState(): string
278
    {
279
        return $this->state;
280
    }
281
282
    /**
283
     * State of the bookable
284
     *
285
     * @API\Input(type="BookableState")
286
     *
287
     * @param string $state
288
     */
289
    public function setState(string $state): void
290
    {
291
        $this->state = $state;
292
    }
293
294
    /**
295
     * The date then the bookable was last checked
296
     *
297
     * @return null|Date
298
     */
299
    public function getVerificationDate(): ?Date
300
    {
301
        return $this->verificationDate;
302
    }
303
304
    /**
305
     * The date then the bookable was last checked
306
     *
307
     * @param null|Date $verificationDate
308
     */
309
    public function setVerificationDate(?Date $verificationDate): void
310
    {
311
        $this->verificationDate = $verificationDate;
312
    }
313
314
    /**
315
     * @return Collection
316
     */
317
    public function getBookableTags(): Collection
318
    {
319
        return $this->bookableTags;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->bookableTags returns the type Application\Model\BookableTag which is incompatible with the type-hinted return Doctrine\Common\Collections\Collection.
Loading history...
320
    }
321
322
    /**
323
     * Notify the user that it has a new bookableTag.
324
     * This should only be called by BookableTag::addUser()
325
     *
326
     * @param BookableTag $bookableTag
327
     */
328
    public function bookableTagAdded(BookableTag $bookableTag): void
329
    {
330
        $this->bookableTags->add($bookableTag);
0 ignored issues
show
Bug introduced by
The method add() does not exist on Application\Model\BookableTag. ( Ignorable by Annotation )

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

330
        $this->bookableTags->/** @scrutinizer ignore-call */ 
331
                             add($bookableTag);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
331
    }
332
333
    /**
334
     * Notify the user that it a bookableTag was removed.
335
     * This should only be called by BookableTag::removeUser()
336
     *
337
     * @param BookableTag $bookableTag
338
     */
339
    public function bookableTagRemoved(BookableTag $bookableTag): void
340
    {
341
        $this->bookableTags->removeElement($bookableTag);
0 ignored issues
show
Bug introduced by
The method removeElement() does not exist on Application\Model\BookableTag. ( Ignorable by Annotation )

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

341
        $this->bookableTags->/** @scrutinizer ignore-call */ 
342
                             removeElement($bookableTag);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
342
    }
343
344
    /**
345
     * @return Collection
346
     */
347 1
    public function getTransactions(): Collection
348
    {
349 1
        return $this->transactions;
350
    }
351
352
    /**
353
     * Notify the bookable that it has a new transaction.
354
     * This should only be called by Transaction::setBookable()
355
     *
356
     * @param Transaction $transaction
357
     */
358 1
    public function transactionAdded(Transaction $transaction): void
359
    {
360 1
        $this->transactions->add($transaction);
361 1
    }
362
363
    /**
364
     * Notify the bookable that one of its transactions was removed
365
     * This should only be called by Transaction::setBookable()
366
     *
367
     * @param Transaction $transaction
368
     */
369 1
    public function transactionRemoved(Transaction $transaction): void
370
    {
371 1
        $this->transactions->removeElement($transaction);
372 1
    }
373
374
    /**
375
     * @return null|Image
376
     */
377
    public function getImage(): ?Image
378
    {
379
        return $this->image;
380
    }
381
382
    /**
383
     * @param null|Image $image
384
     */
385
    public function setImage(?Image $image): void
386
    {
387
        $this->image = $image;
388
    }
389
}
390