Failed Conditions
Push — master ( 5fbadf...673c47 )
by Adrien
07:14
created

Bookable::transactionRemoved()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\ManyToMany(targetEntity="License", mappedBy="bookables")
95
     */
96
    private $licenses;
97
98
    /**
99
     * @var null|Image
100
     * @ORM\OneToOne(targetEntity="Image", orphanRemoval=true)
101
     * @ORM\JoinColumn(name="image_id", referencedColumnName="id")
102
     */
103
    private $image;
104
105
    /**
106
     * Constructor
107
     */
108 5
    public function __construct()
109
    {
110 5
        $this->bookings = new ArrayCollection();
111 5
        $this->licenses = new ArrayCollection();
112 5
        $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...
113 5
    }
114
115
    /**
116
     * @return Collection
117
     */
118 1
    public function getBookings(): Collection
119
    {
120 1
        return $this->bookings;
121
    }
122
123
    /**
124
     * Notify the bookable that it has a new booking.
125
     * This should only be called by Booking::addBookable()
126
     *
127
     * @param Booking $booking
128
     */
129 2
    public function bookingAdded(Booking $booking): void
130
    {
131 2
        $this->bookings->add($booking);
132 2
    }
133
134
    /**
135
     * Notify the bookable that it a booking was removed.
136
     * This should only be called by Booking::removeBookable()
137
     *
138
     * @param Booking $booking
139
     */
140 1
    public function bookingRemoved(Booking $booking): void
141
    {
142 1
        $this->bookings->removeElement($booking);
143 1
    }
144
145
    /**
146
     * @return Collection
147
     */
148 1
    public function getLicenses(): Collection
149
    {
150 1
        return $this->licenses;
151
    }
152
153
    /**
154
     * Notify the bookable that it has a new license.
155
     * This should only be called by License::addBookable()
156
     *
157
     * @param License $license
158
     */
159 1
    public function licenseAdded(License $license): void
160
    {
161 1
        $this->licenses->add($license);
162 1
    }
163
164
    /**
165
     * Notify the bookable that it a license was removed.
166
     * This should only be called by License::removeBookable()
167
     *
168
     * @param License $license
169
     */
170 1
    public function licenseRemoved(License $license): void
171
    {
172 1
        $this->licenses->removeElement($license);
173 1
    }
174
175
    /**
176
     * @return string
177
     */
178
    public function getInitialPrice(): string
179
    {
180
        return $this->initialPrice;
181
    }
182
183
    /**
184
     * @param string $initialPrice
185
     */
186
    public function setInitialPrice(string $initialPrice): void
187
    {
188
        $this->initialPrice = $initialPrice;
189
    }
190
191
    /**
192
     * @return string
193
     */
194
    public function getPeriodicPrice(): string
195
    {
196
        return $this->periodicPrice;
197
    }
198
199
    /**
200
     * @param string $periodicPrice
201
     */
202
    public function setPeriodicPrice(string $periodicPrice): void
203
    {
204
        $this->periodicPrice = $periodicPrice;
205
    }
206
207
    /**
208
     * @return int
209
     */
210
    public function getSimultaneousBookingMaximum(): int
211
    {
212
        return $this->simultaneousBookingMaximum;
213
    }
214
215
    /**
216
     * @param int $simultaneousBookingMaximum
217
     */
218
    public function setSimultaneousBookingMaximum(int $simultaneousBookingMaximum): void
219
    {
220
        $this->simultaneousBookingMaximum = $simultaneousBookingMaximum;
221
    }
222
223
    /**
224
     * @API\Field(type="BookingType")
225
     *
226
     * @return string
227
     */
228
    public function getBookingType(): string
229
    {
230
        return $this->bookingType;
231
    }
232
233
    /**
234
     * Whether this bookable can be booked
235
     *
236
     * @return bool
237
     */
238
    public function isActive(): bool
239
    {
240
        return $this->isActive;
241
    }
242
243
    /**
244
     * Whether this bookable can be booked
245
     *
246
     * @param bool $isActive
247
     */
248
    public function setIsActive(bool $isActive): void
249
    {
250
        $this->isActive = $isActive;
251
    }
252
253
    /**
254
     * @API\Input(type="BookingType")
255
     *
256
     * @param string $state
257
     */
258
    public function setBookingType(string $state): void
259
    {
260
        $this->bookingType = $state;
261
    }
262
263
    /**
264
     * State of the bookable
265
     *
266
     * @API\Field(type="BookableState")
267
     *
268
     * @return string
269
     */
270
    public function getState(): string
271
    {
272
        return $this->state;
273
    }
274
275
    /**
276
     * State of the bookable
277
     *
278
     * @API\Input(type="BookableState")
279
     *
280
     * @param string $state
281
     */
282
    public function setState(string $state): void
283
    {
284
        $this->state = $state;
285
    }
286
287
    /**
288
     * The date then the bookable was last checked
289
     *
290
     * @return null|Date
291
     */
292
    public function getVerificationDate(): ?Date
293
    {
294
        return $this->verificationDate;
295
    }
296
297
    /**
298
     * The date then the bookable was last checked
299
     *
300
     * @param null|Date $verificationDate
301
     */
302
    public function setVerificationDate(?Date $verificationDate): void
303
    {
304
        $this->verificationDate = $verificationDate;
305
    }
306
307
    /**
308
     * @return Collection
309
     */
310
    public function getBookableTags(): Collection
311
    {
312
        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...
313
    }
314
315
    /**
316
     * Notify the user that it has a new bookableTag.
317
     * This should only be called by BookableTag::addUser()
318
     *
319
     * @param BookableTag $bookableTag
320
     */
321
    public function bookableTagAdded(BookableTag $bookableTag): void
322
    {
323
        $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

323
        $this->bookableTags->/** @scrutinizer ignore-call */ 
324
                             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...
324
    }
325
326
    /**
327
     * Notify the user that it a bookableTag was removed.
328
     * This should only be called by BookableTag::removeUser()
329
     *
330
     * @param BookableTag $bookableTag
331
     */
332
    public function bookableTagRemoved(BookableTag $bookableTag): void
333
    {
334
        $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

334
        $this->bookableTags->/** @scrutinizer ignore-call */ 
335
                             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...
335
    }
336
337
    /**
338
     * @return null|Image
339
     */
340
    public function getImage(): ?Image
341
    {
342
        return $this->image;
343
    }
344
345
    /**
346
     * @param null|Image $image
347
     */
348
    public function setImage(?Image $image): void
349
    {
350
        $this->image = $image;
351
    }
352
}
353