Completed
Pull Request — master (#136)
by
unknown
18:39 queued 10:37
created

PerformanceEvent::addPriceCategory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\Common\Collections\Collection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Gedmo\Mapping\Annotation as Gedmo;
9
use Gedmo\Blameable\Traits\BlameableEntity;
10
use JMS\Serializer\Annotation as Serializer;
11
use Symfony\Component\Validator\Constraints as Assert;
12
use AppBundle\Traits\TimestampableTrait;
13
use AppBundle\Traits\DeletedByTrait;
14
use JMS\Serializer\Annotation\ExclusionPolicy;
15
use JMS\Serializer\Annotation\Expose;
16
use JMS\Serializer\Annotation\Type;
17
use JMS\Serializer\Annotation\Accessor;
18
use AppBundle\Validator\TwoPerformanceEventsPerDay;
19
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface;
20
use Sonata\TranslationBundle\Model\Gedmo\AbstractPersonalTranslatable;
21
22
/**
23
 * @ORM\Table(name="performance_schedule")
24
 * @ORM\Entity(repositoryClass="AppBundle\Repository\PerformanceEventRepository")
25
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
26
 * @ExclusionPolicy("all")
27
 * @Gedmo\TranslationEntity(class="AppBundle\Entity\Translations\PerformanceEventTranslation")
28
 * @TwoPerformanceEventsPerDay()
29
 */
30
class PerformanceEvent extends AbstractPersonalTranslatable implements TranslatableInterface
31
{
32
    use TimestampableTrait, BlameableEntity, DeletedByTrait;
33
34
    /**
35
     * @var integer
36
     *
37
     * @ORM\Column(name="id", type="integer")
38
     * @ORM\Id
39
     * @ORM\GeneratedValue(strategy="AUTO")
40
     *
41
     * @Serializer\Groups({"get_ticket"})
42
     * @Type("integer")
43
     * @Expose
44
     */
45
    private $id;
46
47
    /**
48
     * @var Performance
49
     *
50
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Performance", inversedBy="performanceEvents")
51
     *
52
     * @Serializer\Groups({"get_ticket"})
53
     * @Type("AppBundle\Entity\Performance")
54
     * @Expose
55
     */
56
    private $performance;
57
58
    /**
59
     * @var /Datetime
60
     *
61
     * @Assert\NotBlank()
62
     * @ORM\Column(type="datetime")
63
     *
64
     * @Serializer\Groups({"get_ticket"})
65
     * @Type("DateTime")
66
     * @Expose
67
     */
68
    private $dateTime;
69
70
    /**
71
     * @var Venue
72
     *
73
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Venue", inversedBy="performanceEvents")
74
     *
75
     * @Serializer\Groups({"get_ticket"})
76
     * @Type("AppBundle\Entity\Venue")
77
     * @Expose
78
     */
79
    private $venue;
80
81
    /**
82
     * @var int
83
     *
84
     * @Serializer\Groups({"get_ticket"})
85
     * @Type("integer")
86
     * @Expose
87
     * @Accessor(getter="getYear")
88
     */
89
    private $year;
90
91
    /**
92
     * @var int
93
     *
94
     * @Serializer\Groups({"get_ticket"})
95
     * @Expose
96
     * @Accessor(getter="getMonth")
97
     */
98
    private $month;
99
100
    /**
101
     * @var int
102
     *
103
     * @Serializer\Groups({"get_ticket"})
104
     * @Expose
105
     * @Accessor(getter="getDay")
106
     */
107
    private $day;
108
109
    /**
110
     * @var string
111
     *
112
     * @Serializer\Groups({"get_ticket"})
113
     * @Expose
114
     * @Accessor(getter="getTime")
115
     */
116
    private $time;
117
118
    /**
119
     * @var ArrayCollection|Translation[]
120
     *
121
     * @ORM\OneToMany(
122
     *     targetEntity="AppBundle\Entity\Translations\PerformanceEventTranslation",
123
     *     mappedBy="object",
124
     *     cascade={"persist", "remove"}
125
     * )
126
     */
127
    protected $translations;
128
129
    /**
130
     * @var PriceCategory[]
131
     *
132
     * @Assert\Valid
133
     * @ORM\OneToMany(
134
     *     targetEntity="AppBundle\Entity\PriceCategory",
135
     *     mappedBy="performanceEvent",
136
     *     cascade={"all"},
137
     *     orphanRemoval=true
138
     * )
139
     */
140
    protected $priceCategories;
141
142 8
    public function __construct()
143
    {
144 8
        parent::__construct();
145 8
        $this->priceCategories = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array<integer,object<App...\Entity\PriceCategory>> of property $priceCategories.

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...
146 8
    }
147
148
    /**
149
     * Unset translations
150
     *
151
     * @return PerformanceEvent
152
     */
153 4
    public function unsetTranslations()
154
    {
155 4
        $this->translations = null;
156
157 4
        return $this;
158
    }
159
160
    /**
161
     * Get id
162
     *
163
     * @return integer
164
     */
165 10
    public function getId()
166
    {
167 10
        return $this->id;
168
    }
169
170
    /**
171
     * Set dateTime
172
     *
173
     * @param  \DateTime        $dateTime
174
     * @return PerformanceEvent
175
     */
176 7
    public function setDateTime($dateTime)
177
    {
178 7
        $this->dateTime = $dateTime;
179
180 7
        return $this;
181
    }
182
183
    /**
184
     * Get dateTime
185
     *
186
     * @return \DateTime
187
     */
188 14
    public function getDateTime()
189
    {
190 14
        return $this->dateTime;
191
    }
192
193
    /**
194
     * Set performance
195
     *
196
     * @param  \AppBundle\Entity\Performance $performance
197
     * @return PerformanceEvent
198
     */
199
    public function setPerformance(\AppBundle\Entity\Performance $performance = null)
200
    {
201
        $this->performance = $performance;
202
203
        return $this;
204
    }
205
206
    /**
207
     * Get performance
208
     *
209
     * @return \AppBundle\Entity\Performance
210
     */
211 6
    public function getPerformance()
212
    {
213 6
        return $this->performance;
214
    }
215
216 2
    public function __toString()
217
    {
218 2
        if ($this->getDateTime()) {
219 1
            return $this->getDateTime()->format('d-m-Y H:i');
220
        }
221
222 1
        return date("F j, Y, g:i a");
223
    }
224
225
    /**
226
     * @return mixed
227
     */
228 4
    public function getYear()
229
    {
230 4
        return $this->getDateTime()->format('Y');
231
    }
232
233
    /**
234
     * @param mixed $year
235
     */
236
    public function setYear($year)
237
    {
238
        $this->year = $year;
239
    }
240
241
    /**
242
     * @return int
243
     */
244 4
    public function getMonth()
245
    {
246 4
        return $this->getDateTime()->format('n');
247
    }
248
249
    /**
250
     * @param int $month
251
     */
252
    public function setMonth($month)
253
    {
254
        $this->month = $month;
255
    }
256
257
    /**
258
     * @return int
259
     */
260 4
    public function getDay()
261
    {
262 4
        return $this->getDateTime()->format('j');
263
    }
264
265
    /**
266
     * @param int $day
267
     */
268
    public function setDay($day)
269
    {
270
        $this->day = $day;
271
    }
272
273
    /**
274
     * @return string
275
     */
276 4
    public function getTime()
277
    {
278 4
        return $this->getDateTime()->format('G:i');
279
    }
280
281
    /**
282
     * @param string $time
283
     */
284
    public function setTime($time)
285
    {
286
        $this->time = $time;
287
    }
288
289
    /**
290
     * @return Venue
291
     */
292 6
    public function getVenue()
293
    {
294 6
        return $this->venue;
295
    }
296
297
    /**
298
     * @param Venue $venue
299
     * @return PerformanceEvent
300
     */
301
    public function setVenue(Venue $venue)
302
    {
303
        $this->venue = $venue;
304
305
        return $this;
306
    }
307
308
    /**
309
     * @param  PriceCategory $priceCategory
310
     * @return PerformanceEvent
311
     */
312
    public function addPriceCategory(PriceCategory $priceCategory)
313
    {
314
        $this->priceCategories[] = $priceCategory;
315
316
        return $this;
317
    }
318
319
    /**
320
     * @param PriceCategory $priceCategory
321
     */
322
    public function removePriceCategories(PriceCategory $priceCategory)
323
    {
324
        $this->priceCategories->removeElement($priceCategory);
0 ignored issues
show
Bug introduced by
The method removeElement cannot be called on $this->priceCategories (of type array<integer,object<App...\Entity\PriceCategory>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
325
    }
326
327
    /**
328
     * @return Collection
329
     */
330 1
    public function getPriceCategories()
331
    {
332 1
        return $this->priceCategories;
333
    }
334
335
    /**
336
     * @param PriceCategory[]|ArrayCollection $priceCategory
337
     */
338
    public function setPriceCategories($priceCategory)
339
    {
340
        $this->priceCategories = $priceCategory;
0 ignored issues
show
Documentation Bug introduced by
It seems like $priceCategory can also be of type object<Doctrine\Common\C...ctions\ArrayCollection>. However, the property $priceCategories is declared as type array<integer,object<App...\Entity\PriceCategory>>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
341
    }
342
}
343