Passed
Push — master ( 623796...c51e01 )
by Adrien
14:55
created

Bookable::getImage()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 2
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 string
47
     *
48
     * @ORM\Column(type="decimal", precision=7, scale=2, options={"default" = "0.00"})
49
     */
50
    private $purchasePrice = '0';
51
52
    /**
53
     * @var int
54
     *
55
     * @ORM\Column(type="smallint", options={"default" = "-1"})
56
     */
57
    private $simultaneousBookingMaximum = 1;
58
59
    /**
60
     * @var string
61
     *
62
     * @ORM\Column(type="BookingType", length=10, options={"default" = BookingTypeType::SELF_APPROVED})
63
     */
64
    private $bookingType = BookingTypeType::SELF_APPROVED;
65
66
    /**
67
     * @var bool
68
     *
69
     * @ORM\Column(type="boolean", options={"default" = 1})
70
     */
71
    private $isActive = true;
72
73
    /**
74
     * @var string
75
     *
76
     * @ORM\Column(type="BookableState", length=10, options={"default" = BookableStateType::GOOD})
77
     */
78
    private $state = BookableStateType::GOOD;
79
80
    /**
81
     * @var null|Date
82
     * @ORM\Column(type="date", nullable=true)
83
     */
84
    private $verificationDate;
85
86
    /**
87
     * @var BookableTag
88
     *
89
     * @ORM\ManyToMany(targetEntity="BookableTag", mappedBy="bookables")
90
     */
91
    private $bookableTags;
92
93
    /**
94
     * @var Collection
95
     * @ORM\ManyToMany(targetEntity="Booking", mappedBy="bookables")
96
     */
97
    private $bookings;
98
99
    /**
100
     * @var Collection
101
     * @ORM\ManyToMany(targetEntity="License", mappedBy="bookables")
102
     */
103
    private $licenses;
104
105
    /**
106
     * @var null|Image
107
     * @ORM\OneToOne(targetEntity="Image", orphanRemoval=true)
108 5
     * @ORM\JoinColumn(name="image_id", referencedColumnName="id")
109
     */
110 5
    private $image;
111 5
112 5
    /**
113 5
     * Constructor
114
     */
115
    public function __construct()
116
    {
117
        $this->bookings = new ArrayCollection();
118 1
        $this->licenses = new ArrayCollection();
119
        $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...
120 1
    }
121
122
    /**
123
     * @return Collection
124
     */
125
    public function getBookings(): Collection
126
    {
127
        return $this->bookings;
128
    }
129 2
130
    /**
131 2
     * Notify the bookable that it has a new booking.
132 2
     * This should only be called by Booking::addBookable()
133
     *
134
     * @param Booking $booking
135
     */
136
    public function bookingAdded(Booking $booking): void
137
    {
138
        $this->bookings->add($booking);
139
    }
140 1
141
    /**
142 1
     * Notify the bookable that it a booking was removed.
143 1
     * This should only be called by Booking::removeBookable()
144
     *
145
     * @param Booking $booking
146
     */
147
    public function bookingRemoved(Booking $booking): void
148 1
    {
149
        $this->bookings->removeElement($booking);
150 1
    }
151
152
    /**
153
     * @return Collection
154
     */
155
    public function getLicenses(): Collection
156
    {
157
        return $this->licenses;
158
    }
159 1
160
    /**
161 1
     * Notify the bookable that it has a new license.
162 1
     * This should only be called by License::addBookable()
163
     *
164
     * @param License $license
165
     */
166
    public function licenseAdded(License $license): void
167
    {
168
        $this->licenses->add($license);
169
    }
170 1
171
    /**
172 1
     * Notify the bookable that it a license was removed.
173 1
     * This should only be called by License::removeBookable()
174
     *
175
     * @param License $license
176
     */
177
    public function licenseRemoved(License $license): void
178
    {
179
        $this->licenses->removeElement($license);
180
    }
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 string
216
     */
217
    public function getPurchasePrice(): string
218
    {
219
        return $this->purchasePrice;
220
    }
221
222
    /**
223
     * @param string $purchasePrice
224
     */
225
    public function setPurchasePrice(string $purchasePrice): void
226
    {
227
        $this->purchasePrice = $purchasePrice;
228
    }
229
230
    /**
231
     * @return int
232
     */
233
    public function getSimultaneousBookingMaximum(): int
234
    {
235
        return $this->simultaneousBookingMaximum;
236
    }
237
238
    /**
239
     * @param int $simultaneousBookingMaximum
240
     */
241
    public function setSimultaneousBookingMaximum(int $simultaneousBookingMaximum): void
242
    {
243
        $this->simultaneousBookingMaximum = $simultaneousBookingMaximum;
244
    }
245
246
    /**
247
     * @API\Field(type="BookingType")
248
     *
249
     * @return string
250
     */
251
    public function getBookingType(): string
252
    {
253
        return $this->bookingType;
254
    }
255
256
    /**
257
     * Whether this bookable can be booked
258
     *
259
     * @return bool
260
     */
261
    public function isActive(): bool
262
    {
263
        return $this->isActive;
264
    }
265
266
    /**
267
     * Whether this bookable can be booked
268
     *
269
     * @param bool $isActive
270
     */
271
    public function setIsActive(bool $isActive): void
272
    {
273
        $this->isActive = $isActive;
274
    }
275
276
    /**
277
     * @API\Input(type="BookingType")
278
     *
279
     * @param string $state
280
     */
281
    public function setBookingType(string $state): void
282
    {
283
        $this->bookingType = $state;
284
    }
285
286
    /**
287
     * State of the bookable
288
     *
289
     * @API\Field(type="BookableState")
290
     *
291
     * @return string
292
     */
293
    public function getState(): string
294
    {
295
        return $this->state;
296
    }
297
298
    /**
299
     * State of the bookable
300
     *
301
     * @API\Input(type="BookableState")
302
     *
303
     * @param string $state
304
     */
305
    public function setState(string $state): void
306
    {
307
        $this->state = $state;
308
    }
309
310
    /**
311
     * The date then the bookable was last checked
312
     *
313
     * @return null|Date
314
     */
315
    public function getVerificationDate(): ?Date
316
    {
317
        return $this->verificationDate;
318
    }
319
320
    /**
321
     * The date then the bookable was last checked
322
     *
323
     * @param null|Date $verificationDate
324
     */
325
    public function setVerificationDate(?Date $verificationDate): void
326
    {
327
        $this->verificationDate = $verificationDate;
328
    }
329
330
    /**
331
     * @return Collection
332
     */
333
    public function getBookableTags(): Collection
334
    {
335
        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...
336
    }
337
338
    /**
339
     * Notify the user that it has a new bookableTag.
340 1
     * This should only be called by BookableTag::addUser()
341
     *
342 1
     * @param BookableTag $bookableTag
343
     */
344
    public function bookableTagAdded(BookableTag $bookableTag): void
345
    {
346
        $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

346
        $this->bookableTags->/** @scrutinizer ignore-call */ 
347
                             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...
347
    }
348 1
349
    /**
350
     * Notify the user that it a bookableTag was removed.
351
     * This should only be called by BookableTag::removeUser()
352 1
     *
353 1
     * @param BookableTag $bookableTag
354
     */
355
    public function bookableTagRemoved(BookableTag $bookableTag): void
356 1
    {
357 1
        $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

357
        $this->bookableTags->/** @scrutinizer ignore-call */ 
358
                             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...
358
    }
359
360
    /**
361
     * @return null|Image
362
     */
363
    public function getImage(): ?Image
364
    {
365
        return $this->image;
366
    }
367
368
    /**
369
     * @param null|Image $image
370
     */
371
    public function setImage(?Image $image): void
372
    {
373
        // We must trigger lazy loading, otherwise Doctrine will seriously
374
        // mess up lifecycle callbacks and delete unrelated image on disk
375
        if ($this->image) {
376
            $this->image->getFilename();
377
        }
378
379
        $this->image = $image;
380
    }
381
}
382