Passed
Push — master ( 8116cf...9d59f1 )
by Adrien
06:29
created

Bookable::getTransactions()   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 0
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\BookingTypeType;
8
use Application\Traits\HasCode;
9
use Application\Traits\HasDescription;
10
use Application\Traits\HasName;
11
use Application\Traits\HasRemarks;
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\Common\Collections\Collection;
14
use Doctrine\ORM\Mapping as ORM;
15
use GraphQL\Doctrine\Annotation as API;
16
17
/**
18
 * An item that can be booked by a user
19
 *
20
 * @ORM\Entity(repositoryClass="Application\Repository\BookableRepository")
21
 */
22
class Bookable extends AbstractModel
23
{
24
    use HasName;
25
    use HasDescription;
26
    use HasCode;
27
    use HasRemarks;
28
29
    /**
30
     * @var string
31
     *
32
     * @ORM\Column(type="decimal", length=10, options={"default" = "0"})
33
     */
34
    private $initialPrice = '0.00';
35
36
    /**
37
     * @var string
38
     *
39
     * @ORM\Column(type="decimal", length=10, options={"default" = "0"})
40
     */
41
    private $periodicPrice = '0.00';
42
43
    /**
44
     * @var int
45
     *
46
     * @ORM\Column(type="smallint", options={"unsigned" = true, "default" = "1"})
47
     */
48
    private $simultaneousBookingMaximum = 1;
49
50
    /**
51
     * @var string
52
     *
53
     * @ORM\Column(type="BookingType", length=10, options={"default" = BookingTypeType::SELF_APPROVED})
54
     */
55
    private $bookingType = BookingTypeType::SELF_APPROVED;
56
57
    /**
58
     * @var BookableTag
59
     *
60
     * @ORM\ManyToMany(targetEntity="BookableTag", mappedBy="bookables")
61
     */
62
    private $bookableTags;
63
64
    /**
65
     * @var Collection
66
     * @ORM\ManyToMany(targetEntity="Booking", mappedBy="bookables")
67
     */
68
    private $bookings;
69
70
    /**
71
     * @var Collection
72
     * @ORM\OneToMany(targetEntity="Transaction", mappedBy="bookable")
73
     */
74
    private $transactions;
75
76
    /**
77
     * @var Collection
78
     * @ORM\ManyToMany(targetEntity="License", mappedBy="bookables")
79
     */
80
    private $licenses;
81
82
    /**
83
     * Constructor
84
     */
85 3
    public function __construct()
86
    {
87 3
        $this->bookings = new ArrayCollection();
88 3
        $this->licenses = new ArrayCollection();
89 3
        $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...
90 3
        $this->transactions = new ArrayCollection();
91 3
    }
92
93
    /**
94
     * @return Collection
95
     */
96 1
    public function getBookings(): Collection
97
    {
98 1
        return $this->bookings;
99
    }
100
101
    /**
102
     * Notify the bookable that it has a new booking.
103
     * This should only be called by Booking::addBookable()
104
     *
105
     * @param Booking $booking
106
     */
107 1
    public function bookingAdded(Booking $booking): void
108
    {
109 1
        $this->bookings->add($booking);
110 1
    }
111
112
    /**
113
     * Notify the bookable that it a booking was removed.
114
     * This should only be called by Booking::removeBookable()
115
     *
116
     * @param Booking $booking
117
     */
118 1
    public function bookingRemoved(Booking $booking): void
119
    {
120 1
        $this->bookings->removeElement($booking);
121 1
    }
122
123
    /**
124
     * @return Collection
125
     */
126 1
    public function getLicenses(): Collection
127
    {
128 1
        return $this->licenses;
129
    }
130
131
    /**
132
     * Notify the bookable that it has a new license.
133
     * This should only be called by License::addBookable()
134
     *
135
     * @param License $license
136
     */
137 1
    public function licenseAdded(License $license): void
138
    {
139 1
        $this->licenses->add($license);
140 1
    }
141
142
    /**
143
     * Notify the bookable that it a license was removed.
144
     * This should only be called by License::removeBookable()
145
     *
146
     * @param License $license
147
     */
148 1
    public function licenseRemoved(License $license): void
149
    {
150 1
        $this->licenses->removeElement($license);
151 1
    }
152
153
    /**
154
     * @return string
155
     */
156
    public function getInitialPrice(): string
157
    {
158
        return $this->initialPrice;
159
    }
160
161
    /**
162
     * @param string $initialPrice
163
     */
164
    public function setInitialPrice(string $initialPrice): void
165
    {
166
        $this->initialPrice = $initialPrice;
167
    }
168
169
    /**
170
     * @return string
171
     */
172
    public function getPeriodicPrice(): string
173
    {
174
        return $this->periodicPrice;
175
    }
176
177
    /**
178
     * @param string $periodicPrice
179
     */
180
    public function setPeriodicPrice(string $periodicPrice): void
181
    {
182
        $this->periodicPrice = $periodicPrice;
183
    }
184
185
    /**
186
     * @return int
187
     */
188
    public function getSimultaneousBookingMaximum(): int
189
    {
190
        return $this->simultaneousBookingMaximum;
191
    }
192
193
    /**
194
     * @param int $simultaneousBookingMaximum
195
     */
196
    public function setSimultaneousBookingMaximum(int $simultaneousBookingMaximum): void
197
    {
198
        $this->simultaneousBookingMaximum = $simultaneousBookingMaximum;
199
    }
200
201
    /**
202
     * @API\Field(type="BookingType")
203
     *
204
     * @return string
205
     */
206
    public function getBookingType(): string
207
    {
208
        return $this->bookingType;
209
    }
210
211
    /**
212
     * @API\Input(type="BookingType")
213
     *
214
     * @param string $bookingType
215
     */
216
    public function setBookingType(string $bookingType): void
217
    {
218
        $this->bookingType = $bookingType;
219
    }
220
221
    /**
222
     * @return Collection
223
     */
224
    public function getBookableTags(): Collection
225
    {
226
        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...
227
    }
228
229
    /**
230
     * Notify the user that it has a new bookableTag.
231
     * This should only be called by BookableTag::addUser()
232
     *
233
     * @param BookableTag $bookableTag
234
     */
235
    public function bookableTagAdded(BookableTag $bookableTag): void
236
    {
237
        $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

237
        $this->bookableTags->/** @scrutinizer ignore-call */ 
238
                             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...
238
    }
239
240
    /**
241
     * Notify the user that it a bookableTag was removed.
242
     * This should only be called by BookableTag::removeUser()
243
     *
244
     * @param BookableTag $bookableTag
245
     */
246
    public function bookableTagRemoved(BookableTag $bookableTag): void
247
    {
248
        $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

248
        $this->bookableTags->/** @scrutinizer ignore-call */ 
249
                             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...
249
    }
250
251
    /**
252
     * @return Collection
253
     */
254 1
    public function getTransactions(): Collection
255
    {
256 1
        return $this->transactions;
257
    }
258
259
    /**
260
     * Notify the bookable that it has a new transaction.
261
     * This should only be called by Transaction::setBookable()
262
     *
263
     * @param Transaction $transaction
264
     */
265 1
    public function transactionAdded(Transaction $transaction): void
266
    {
267 1
        $this->transactions->add($transaction);
268 1
    }
269
270
    /**
271
     * Notify the bookable that one of its transactions was removed
272
     * This should only be called by Transaction::setBookable()
273
     *
274
     * @param Transaction $transaction
275
     */
276 1
    public function transactionRemoved(Transaction $transaction): void
277
    {
278 1
        $this->transactions->removeElement($transaction);
279 1
    }
280
}
281