Ticket   A
last analyzed

Complexity

Total Complexity 32

Size/Duplication

Total Lines 331
Duplicated Lines 5.74 %

Coupling/Cohesion

Components 5
Dependencies 2

Importance

Changes 0
Metric Value
wmc 32
lcom 5
cbo 2
dl 19
loc 331
rs 9.6
c 0
b 0
f 0

26 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A getEmail() 0 4 1
A __toString() 12 12 2
A isSaturday() 0 4 1
A getDay() 0 4 1
A isSunday() 0 4 1
A getCode() 0 4 1
A setCode() 0 4 1
A getName() 0 4 1
A setEmail() 0 4 1
A setDay() 0 7 2
A getEvent() 0 4 1
A setEvent() 0 4 1
A setName() 0 4 1
A isCheckedIn() 0 4 1
A getCheckinTime() 0 4 1
A setCheckedIn() 0 4 2
A setType() 7 7 2
A getType() 0 4 1
A getLabel() 0 10 3
A setNotified() 0 4 1
A isNotified() 0 4 1
A isPrinted() 0 4 1
A isPaid() 0 4 1
A setPayment() 0 4 1
A getPayment() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace BCRM\BackendBundle\Entity\Event;
4
5
use BCRM\BackendBundle\Entity\Payment;
6
use BCRM\BackendBundle\Exception\InvalidArgumentException;
7
use Doctrine\ORM\Mapping as ORM;
8
use Gedmo\Mapping\Annotation as Gedmo;
9
use LiteCQRS\Plugin\CRUD\AggregateResource;
10
use Symfony\Component\Validator\Constraints as Assert;
11
12
13
/**
14
 * Ticket
15
 *
16
 * @ORM\Table(name="ticket",indexes={@ORM\Index(name="email_idx", columns={"email"})}, uniqueConstraints={@ORM\UniqueConstraint(name="event_email_day",columns={"event_id", "email", "day"})})
17
 * @ORM\Entity(repositoryClass="BCRM\BackendBundle\Entity\Event\DoctrineTicketRepository")
18
 */
19
class Ticket extends AggregateResource
20
{
21
    const DAY_SATURDAY = 1;
22
23
    const DAY_SUNDAY = 2;
24
25
    /**
26
     * @var integer
27
     * @ORM\Column(name="id", type="integer")
28
     * @ORM\Id
29
     * @ORM\GeneratedValue(strategy="AUTO")
30
     */
31
    protected $id;
32
33
    /**
34
     * @Assert\NotBlank()
35
     * @ORM\ManyToOne(targetEntity="BCRM\BackendBundle\Entity\Event\Event", inversedBy="tickets")
36
     * @ORM\JoinColumn(name="event_id", referencedColumnName="id", nullable=false)
37
     * @var Event
38
     */
39
    protected $event;
40
41
    /**
42
     * @var string
43
     * @Assert\NotBlank()
44
     * @ORM\Column(type="text")
45
     */
46
    protected $name;
47
48
    /**
49
     * @var string
50
     * @Assert\NotBlank()
51
     * @Assert\Email()
52
     * @ORM\Column(type="string")
53
     */
54
    protected $email;
55
56
    /**
57
     * @var integer
58
     * @Assert\NotBlank()
59
     * @Assert\Type(type="integer")
60
     * @Assert\Range(min=1,max=2)
61
     * @ORM\Column(type="integer")
62
     */
63
    protected $day;
64
65
    /**
66
     * @ORM\Column(type="string", nullable=false, name="code")
67
     * @var string Ticket code
68
     */
69
    protected $code;
70
71
    /**
72
     * @ORM\ManyToOne(targetEntity="BCRM\BackendBundle\Entity\Payment")
73
     * @ORM\JoinColumn(name="payment_id", referencedColumnName="id", nullable=true)
74
     * @var Payment
75
     */
76
    protected $payment;
77
78
    /**
79
     * @var boolean
80
     * @Assert\NotBlank()
81
     * @Assert\Type(type="boolean")
82
     * @ORM\Column(type="boolean")
83
     */
84
    protected $notified = 0;
85
86
    /**
87
     * @var boolean
88
     * @ORM\Column(type="datetime", name="checked_in", nullable=true)
89
     * @var \DateTime
90
     * @Assert\Type(type="\DateTime")
91
     */
92
    protected $checkedIn;
93
94
    /**
95
     * @var boolean
96
     * @Assert\Type(type="boolean")
97
     * @ORM\Column(type="boolean")
98
     */
99
    protected $printed = 0;
100
101
    /**
102
     * @var integer
103
     * @Assert\NotBlank()
104
     * @Assert\Type(type="integer")
105
     * @ORM\Column(type="integer")
106
     */
107
    protected $type = Registration::TYPE_NORMAL;
108
109
    /**
110
     * @Gedmo\Timestampable(on="create")
111
     * @ORM\Column(type="datetime")
112
     * @var \DateTime
113
     */
114
    protected $created;
115
116
    /**
117
     * @Gedmo\Timestampable(on="update")
118
     * @ORM\Column(type="datetime", nullable=true)
119
     * @var \DateTime
120
     */
121
    protected $updated;
122
123
    /**
124
     * Get id
125
     *
126
     * @return integer
127
     */
128
    public function getId()
129
    {
130
        return $this->id;
131
    }
132
133
    /**
134
     * @return string
135
     */
136
    public function getEmail()
137
    {
138
        return $this->email;
139
    }
140
141
    /**
142
     * @param string $email
143
     */
144
    public function setEmail($email)
145
    {
146
        $this->email = $email;
147
    }
148
149
    /**
150
     * @return string
151
     */
152 View Code Duplication
    public function __toString()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
153
    {
154
        $str  = $this->email;
155
        $days = array();
156
        if ($this->day === static::DAY_SATURDAY) {
157
            $days[] = 'SA';
158
        } else {
159
            $days[] = 'SU';
160
        }
161
        $str .= ' (' . join('+', $days) . ')';
162
        return $str;
163
    }
164
165
    /**
166
     * @return bool
167
     */
168
    public function isSaturday()
169
    {
170
        return $this->getDay() === static::DAY_SATURDAY;
171
    }
172
173
    /**
174
     * @return int
175
     */
176
    public function getDay()
177
    {
178
        return $this->day;
179
    }
180
181
    /**
182
     * @param int $day
183
     */
184
    public function setDay($day)
185
    {
186
        if (!in_array($day, array(static::DAY_SATURDAY, static::DAY_SUNDAY))) {
187
            throw new InvalidArgumentException(sprintf('Invalid day: %d', $day));
188
        }
189
        $this->day = $day;
190
    }
191
192
    /**
193
     * @return bool
194
     */
195
    public function isSunday()
196
    {
197
        return $this->getDay() === static::DAY_SUNDAY;
198
    }
199
200
    /**
201
     * @return \BCRM\BackendBundle\Entity\Event\Event
202
     */
203
    public function getEvent()
204
    {
205
        return $this->event;
206
    }
207
208
    /**
209
     * @param \BCRM\BackendBundle\Entity\Event\Event $event
210
     */
211
    public function setEvent(Event $event)
212
    {
213
        $this->event = $event;
214
    }
215
216
    /**
217
     * @return string
218
     */
219
    public function getCode()
220
    {
221
        return $this->code;
222
    }
223
224
    /**
225
     * @param string $code
226
     */
227
    public function setCode($code)
228
    {
229
        $this->code = $code;
230
    }
231
232
    /**
233
     * @return string
234
     */
235
    public function getName()
236
    {
237
        return $this->name;
238
    }
239
240
    /**
241
     * @param string $name
242
     */
243
    public function setName($name)
244
    {
245
        $this->name = $name;
246
    }
247
248
    public function isCheckedIn()
249
    {
250
        return $this->checkedIn !== null;
251
    }
252
253
    /**
254
     * @return \DateTime|null
255
     */
256
    public function getCheckinTime()
257
    {
258
        return $this->checkedIn;
259
    }
260
261
    /**
262
     * @param boolean $checkedIn
263
     */
264
    public function setCheckedIn($checkedIn)
265
    {
266
        $this->checkedIn = $checkedIn ? new \DateTime() : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like $checkedIn ? new \DateTime() : null can also be of type object<DateTime>. However, the property $checkedIn is declared as type boolean. 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...
267
    }
268
269
    /**
270
     * @param int $type
271
     */
272 View Code Duplication
    public function setType($type)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
273
    {
274
        if (!in_array($type, array(Registration::TYPE_NORMAL, Registration::TYPE_VIP, Registration::TYPE_SPONSOR))) {
275
            throw new \InvalidArgumentException("Invalid type");
276
        }
277
        $this->type = $type;
278
    }
279
280
    /**
281
     * @return int
282
     */
283
    public function getType()
284
    {
285
        return $this->type;
286
    }
287
288
    /**
289
     * @return string
290
     */
291
    public function getLabel()
292
    {
293
        switch ($this->getType()) {
294
            case Registration::TYPE_VIP:
295
                return 'VIP';
296
            case Registration::TYPE_SPONSOR:
297
                return 'Sponsor';
298
        }
299
        return '';
300
    }
301
302
    /**
303
     * @param boolean $notified
304
     */
305
    public function setNotified($notified)
306
    {
307
        $this->notified = (bool)$notified;
308
    }
309
310
    /**
311
     * @return bool
312
     */
313
    public function isNotified()
314
    {
315
        return (bool)$this->notified;
316
    }
317
318
    /**
319
     * @return bool
320
     */
321
    public function isPrinted()
322
    {
323
        return $this->printed;
324
    }
325
326
    /**
327
     * @return boolean
328
     */
329
    public function isPaid()
330
    {
331
        return $this->payment !== null;
332
    }
333
334
    /**
335
     * @param Payment $payment
336
     */
337
    public function setPayment(Payment $payment)
338
    {
339
        $this->payment = $payment;
340
    }
341
342
    /**
343
     * @return Payment
344
     */
345
    public function getPayment()
346
    {
347
        return $this->payment;
348
    }
349
}
350
351
352