GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ArticleTrait   B
last analyzed

Complexity

Total Complexity 45

Size/Duplication

Total Lines 710
Duplicated Lines 1.27 %

Coupling/Cohesion

Components 4
Dependencies 0

Test Coverage

Coverage 61.26%

Importance

Changes 0
Metric Value
wmc 45
lcom 4
cbo 0
dl 9
loc 710
ccs 68
cts 111
cp 0.6126
rs 8
c 0
b 0
f 0

43 Methods

Rating   Name   Duplication   Size   Complexity  
A getArticleNumber() 0 4 1
A setArticleNumber() 0 6 1
A getTitle() 0 4 1
A setTitle() 0 6 1
A getDescription() 0 4 1
A setDescription() 0 6 1
A getTags() 0 6 1
A setTags() 0 6 1
A getUnitPrice() 0 4 1
A setUnitPrice() 0 6 1
A getSetupFee() 0 4 1
A setSetupFee() 0 6 1
A allowsMultiple() 0 4 1
A setAllowMultiple() 0 6 1
A isAddon() 0 4 1
A setIsAddon() 0 6 1
A getTranslation() 0 4 1
A setTranslation() 0 6 1
A getCurrencyCode() 0 4 1
A setCurrencyCode() 0 6 1
A getVatPercent() 0 4 1
A setVatPercent() 9 9 3
A getSubscriptionInterval() 0 4 1
A setSubscriptionInterval() 0 6 1
A getSubscriptionNumberEvents() 0 4 1
A setSubscriptionNumberEvents() 0 6 1
A getSubscriptionTrial() 0 4 1
A setSubscriptionTrial() 0 6 1
A getSubscriptionDuration() 0 4 1
A setSubscriptionDuration() 0 6 1
A getSubscriptionDurationFollow() 0 4 1
A setSubscriptionDurationFollow() 0 6 1
A getSubscriptionCancellationPeriod() 0 4 1
A setSubscriptionCancellationPeriod() 0 6 1
A getReturnUrlSuccess() 0 4 1
A setReturnUrlSuccess() 0 6 1
A getReturnUrlCancel() 0 4 1
A setReturnUrlCancel() 0 6 1
A getCheckoutUrl() 0 4 1
A setCheckoutUrl() 0 6 1
A getFeatures() 0 4 1
A setFeatures() 0 6 1
A addFeature() 0 4 1

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ArticleTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ArticleTrait, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Speicher210\Monsum\Api\Model;
4
5
use JMS\Serializer\Annotation as JMS;
6
7
/**
8
 * Trait for article data.
9
 */
10
trait ArticleTrait
11
{
12
    /**
13
     * The article number.
14
     *
15
     * @var string
16
     *
17
     * @JMS\Type("string")
18
     * @JMS\SerializedName("ARTICLE_NUMBER")
19
     */
20
    protected $articleNumber;
21
22
    /**
23
     * The title of the article.
24
     *
25
     * @var string
26
     *
27
     * @JMS\Type("string")
28
     * @JMS\SerializedName("TITLE")
29
     */
30
    protected $title;
31
32
    /**
33
     * The description of the article.
34
     *
35
     * @var string
36
     *
37
     * @JMS\Type("string")
38
     * @JMS\SerializedName("DESCRIPTION")
39
     */
40
    protected $description;
41
42
    /**
43
     * Article tags.
44
     *
45
     * @var string
46
     *
47
     * @JMS\Type("string")
48
     * @JMS\SerializedName("TAGS")
49
     */
50
    protected $tags;
51
52
    /**
53
     * The unit price.
54
     *
55
     * @var float
56
     *
57
     * @JMS\Type("float")
58
     * @JMS\SerializedName("UNIT_PRICE")
59
     */
60
    protected $unitPrice;
61
62
    /**
63
     * The setup fee.
64
     *
65
     * @var float
66
     *
67
     * @JMS\Type("float")
68
     * @JMS\SerializedName("SETUP_FEE")
69
     */
70
    protected $setupFee;
71
72
    /**
73
     * Allow multiple.
74
     *
75
     * @var integer
76
     *
77
     * @JMS\Type("integer")
78
     * @JMS\SerializedName("ALLOW_MULTIPLE")
79
     */
80
    protected $allowMultiple;
81
82
    /**
83
     * Flag if article is addon.
84
     *
85
     * @var integer
86
     *
87
     * @JMS\Type("integer")
88
     * @JMS\SerializedName("IS_ADDON")
89
     */
90
    protected $isAddon;
91
92
    /**
93
     * Article translations.
94
     *
95
     * @var Translation
96
     *
97
     * @JMS\Type("Speicher210\Monsum\Api\Model\Translation")
98
     * @JMS\SerializedName("TRANSLATIONS")
99
     */
100
    protected $translation;
101
102
    /**
103
     * The currency code.
104
     *
105
     * @var string
106
     *
107
     * @JMS\Type("string")
108
     * @JMS\SerializedName("CURRENCY_CODE")
109
     */
110
    protected $currencyCode;
111
112
    /**
113
     * VAT percent.
114
     *
115
     * @var float
116
     *
117
     * @JMS\Type("float")
118
     * @JMS\SerializedName("VAT_PERCENT")
119
     */
120
    protected $vatPercent;
121
122
    /**
123
     * The subscription interval (ex: "1 month").
124
     *
125
     * @var string
126
     *
127
     * @JMS\Type("string")
128
     * @JMS\SerializedName("SUBSCRIPTION_INTERVAL")
129
     */
130
    protected $subscriptionInterval;
131
132
    /**
133
     * Number of billing events for the subscription.
134
     *
135
     * @var integer
136
     *
137
     * @JMS\Type("integer")
138
     * @JMS\SerializedName("SUBSCRIPTION_NUMBER_EVENTS")
139
     */
140
    protected $subscriptionNumberEvents;
141
142
    /**
143
     * Subscription trial period (ex: "2 day").
144
     *
145
     * @var string
146
     *
147
     * @JMS\Type("string")
148
     * @JMS\SerializedName("SUBSCRIPTION_TRIAL")
149
     */
150
    protected $subscriptionTrial;
151
152
    /**
153
     * Subscription first contract period (ex: "1 month").
154
     *
155
     * @var string
156
     *
157
     * @JMS\Type("string")
158
     * @JMS\SerializedName("SUBSCRIPTION_DURATION")
159
     */
160
    protected $subscriptionDuration;
161
162
    /**
163
     * Subscription following contract period (ex: "1 month").
164
     *
165
     * @var string
166
     *
167
     * @JMS\Type("string")
168
     * @JMS\SerializedName("SUBSCRIPTION_DURATION_FOLLOW")
169
     */
170
    protected $subscriptionDurationFollow;
171
172
    /**
173
     * Subscription cancellation period (ex: "1 day").
174
     *
175
     * @var string
176
     *
177
     * @JMS\Type("string")
178
     * @JMS\SerializedName("SUBSCRIPTION_CANCELLATION")
179
     */
180
    protected $subscriptionCancellationPeriod;
181
182
    /**
183
     * Success URL.
184
     *
185
     * @var string
186
     *
187
     * @JMS\Type("string")
188
     * @JMS\SerializedName("RETURN_URL_SUCCESS")
189
     */
190
    protected $returnUrlSuccess;
191
192
    /**
193
     * Cancel URL.
194
     *
195
     * @var string
196
     *
197
     * @JMS\Type("string")
198
     * @JMS\SerializedName("RETURN_URL_CANCEL")
199
     */
200
    protected $returnUrlCancel;
201
202
    /**
203
     * Checkout URL.
204
     *
205
     * @var string
206
     *
207
     * @JMS\Type("string")
208
     * @JMS\SerializedName("CHECKOUT_URL")
209
     */
210
    protected $checkoutUrl;
211
212
    /**
213
     * Product features.
214
     *
215
     * @var array
216
     *
217
     * @JMS\Type("array<Speicher210\Monsum\Api\Model\Feature>")
218
     * @JMS\SerializedName("FEATURES")
219
     */
220
    protected $features = [];
221
222
    /**
223
     * Get the article number.
224
     *
225
     * @return integer
226
     */
227 9
    public function getArticleNumber()
228
    {
229 9
        return $this->articleNumber;
230
    }
231
232
    /**
233
     * Set the article number.
234
     *
235
     * @param string $articleNumber The article number.
236
     * @return $this
237
     */
238 12
    public function setArticleNumber($articleNumber)
239
    {
240 12
        $this->articleNumber = $articleNumber;
241
242 12
        return $this;
243
    }
244
245
    /**
246
     * Get the title.
247
     *
248
     * @return string
249
     */
250
    public function getTitle()
251
    {
252
        return $this->title;
253
    }
254
255
    /**
256
     * Set the title.
257
     *
258
     * @param string $title The title.
259
     * @return $this
260
     */
261 6
    public function setTitle($title)
262
    {
263 6
        $this->title = $title;
264
265 6
        return $this;
266
    }
267
268
    /**
269
     * Get the description.
270
     *
271
     * @return string
272
     */
273
    public function getDescription()
274
    {
275
        return $this->description;
276
    }
277
278
    /**
279
     * Set the description.
280
     *
281
     * @param string $description The description.
282
     * @return $this
283
     */
284 6
    public function setDescription($description)
285
    {
286 6
        $this->description = $description;
287
288 6
        return $this;
289
    }
290
291
    /**
292
     * Get the tags.
293
     *
294
     * @return array
295
     */
296
    public function getTags()
297
    {
298
        $tags = explode(',', $this->tags);
299
300
        return array_map('trim', $tags);
301
    }
302
303
    /**
304
     * Set the tags.
305
     * #
306
     * @param array $tags The tags to set.
307
     * @return $this
308
     */
309 6
    public function setTags(array $tags)
310
    {
311 6
        $this->tags = implode(', ', $tags);
312
313 6
        return $this;
314
    }
315
316
    /**
317
     * Get the unit price.
318
     *
319
     * @return float
320
     */
321
    public function getUnitPrice()
322
    {
323
        return $this->unitPrice;
324
    }
325
326
    /**
327
     * Set the unit price.
328
     *
329
     * @param float $unitPrice The price.
330
     * @return $this
331
     */
332 6
    public function setUnitPrice($unitPrice)
333
    {
334 6
        $this->unitPrice = $unitPrice;
335
336 6
        return $this;
337
    }
338
339
    /**
340
     * Get the setup fee.
341
     *
342
     * @return float
343
     */
344
    public function getSetupFee()
345
    {
346
        return $this->setupFee;
347
    }
348
349
    /**
350
     * Set the setup fee.
351
     *
352
     * @param float $setupFee The setup fee.
353
     * @return $this
354
     */
355 6
    public function setSetupFee($setupFee)
356
    {
357 6
        $this->setupFee = $setupFee;
358
359 6
        return $this;
360
    }
361
362
    /**
363
     * Check if it allows multiple instances.
364
     *
365
     * @return boolean
366
     */
367
    public function allowsMultiple()
368
    {
369
        return (boolean)$this->allowMultiple;
370
    }
371
372
    /**
373
     * Set if it allows multiple instances.
374
     *
375
     * @param boolean $allowMultiple The flag.
376
     * @return $this
377
     */
378 6
    public function setAllowMultiple($allowMultiple)
379
    {
380 6
        $this->allowMultiple = (integer)(boolean)$allowMultiple;
381
382 6
        return $this;
383
    }
384
385
    /**
386
     * Check if the article is an addon.
387
     *
388
     * @return boolean
389
     */
390
    public function isAddon()
391
    {
392
        return (boolean)$this->isAddon;
393
    }
394
395
    /**
396
     * Set that the article is an addon.
397
     *
398
     * @param boolean $isAddon Flag if the article is an addon.
399
     * @return $this
400
     */
401 6
    public function setIsAddon($isAddon)
402
    {
403 6
        $this->isAddon = (integer)(boolean)$isAddon;
404
405 6
        return $this;
406
    }
407
408
    /**
409
     * Get the translation.
410
     *
411
     * @return Translation
412
     */
413
    public function getTranslation()
414
    {
415
        return $this->translation;
416
    }
417
418
    /**
419
     * Set the translation.
420
     *
421
     * @param Translation $translation The translation to set.
422
     * @return $this
423
     */
424 6
    public function setTranslation(Translation $translation)
425
    {
426 6
        $this->translation = $translation;
427
428 6
        return $this;
429
    }
430
431
    /**
432
     * Get the currency code.
433
     *
434
     * @return string
435
     */
436
    public function getCurrencyCode()
437
    {
438
        return $this->currencyCode;
439
    }
440
441
    /**
442
     * Set the currency code.
443
     *
444
     * @param string $currencyCode The currency code.
445
     * @return $this
446
     */
447 6
    public function setCurrencyCode($currencyCode)
448
    {
449 6
        $this->currencyCode = $currencyCode;
450
451 6
        return $this;
452
    }
453
454
    /**
455
     * Get the VAT percentage.
456
     *
457
     * @return float
458
     */
459
    public function getVatPercent()
460
    {
461
        return $this->vatPercent;
462
    }
463
464
    /**
465
     * Set the VAT percentage.
466
     *
467
     * @param float $vatPercent The VAT percentage.
468
     * @return $this
469
     * @throws \InvalidArgumentException If the percent is not between 0 and 100
470 6
     */
471 View Code Duplication
    public function setVatPercent($vatPercent)
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...
472 6
    {
473
        if ($vatPercent < 0 || $vatPercent > 100) {
474
            throw new \InvalidArgumentException('VAT percentage must be between 0-100');
475 6
        }
476
        $this->vatPercent = $vatPercent;
477 6
478
        return $this;
479
    }
480
481
    /**
482
     * Get the subscription interval.
483
     *
484
     * @return string
485
     */
486
    public function getSubscriptionInterval()
487
    {
488
        return $this->subscriptionInterval;
489
    }
490
491
    /**
492
     * Set the subscription interval.
493
     *
494
     * @param string $subscriptionInterval The interval.
495
     * @return $this
496 6
     */
497
    public function setSubscriptionInterval($subscriptionInterval)
498 6
    {
499
        $this->subscriptionInterval = $subscriptionInterval;
500 6
501
        return $this;
502
    }
503
504
    /**
505
     * Get the subscription number of events.
506
     *
507
     * @return integer
508
     */
509
    public function getSubscriptionNumberEvents()
510
    {
511
        return $this->subscriptionNumberEvents;
512
    }
513
514
    /**
515
     * Set the subscription number of events.
516
     *
517
     * @param integer $subscriptionNumberEvents The number of events.
518
     * @return $this
519 6
     */
520
    public function setSubscriptionNumberEvents($subscriptionNumberEvents)
521 6
    {
522
        $this->subscriptionNumberEvents = $subscriptionNumberEvents;
523 6
524
        return $this;
525
    }
526
527
    /**
528
     * Get the subscription trial.
529
     *
530
     * @return string
531
     */
532
    public function getSubscriptionTrial()
533
    {
534
        return $this->subscriptionTrial;
535
    }
536
537
    /**
538
     * Set the subscription trial.
539
     *
540
     * @param string $subscriptionTrial The subscription trial.
541
     * @return $this
542 6
     */
543
    public function setSubscriptionTrial($subscriptionTrial)
544 6
    {
545
        $this->subscriptionTrial = $subscriptionTrial;
546 6
547
        return $this;
548
    }
549
550
    /**
551
     * Get the subscription duration.
552
     *
553
     * @return string
554
     */
555
    public function getSubscriptionDuration()
556
    {
557
        return $this->subscriptionDuration;
558
    }
559
560
    /**
561
     * Set the subscription duration.
562
     *
563
     * @param string $subscriptionDuration The duration.
564
     * @return $this
565 6
     */
566
    public function setSubscriptionDuration($subscriptionDuration)
567 6
    {
568
        $this->subscriptionDuration = $subscriptionDuration;
569 6
570
        return $this;
571
    }
572
573
    /**
574
     * Get the subscription duration follow.
575
     *
576
     * @return string
577
     */
578
    public function getSubscriptionDurationFollow()
579
    {
580
        return $this->subscriptionDurationFollow;
581
    }
582
583
    /**
584
     * Set the subscription duration follow.
585
     *
586
     * @param string $subscriptionDurationFollow The duration follow.
587
     * @return $this
588 6
     */
589
    public function setSubscriptionDurationFollow($subscriptionDurationFollow)
590 6
    {
591
        $this->subscriptionDurationFollow = $subscriptionDurationFollow;
592 6
593
        return $this;
594
    }
595
596
    /**
597
     * Get the subscription cancellation period.
598
     * @return string
599
     */
600
    public function getSubscriptionCancellationPeriod()
601
    {
602
        return $this->subscriptionCancellationPeriod;
603
    }
604
605
    /**
606
     * Set the subscription cancellation period.
607
     *
608
     * @param string $subscriptionCancellationPeriod The period.
609
     * @return $this
610 6
     */
611
    public function setSubscriptionCancellationPeriod($subscriptionCancellationPeriod)
612 6
    {
613
        $this->subscriptionCancellationPeriod = $subscriptionCancellationPeriod;
614 6
615
        return $this;
616
    }
617
618
    /**
619
     * Get the success return URL.
620
     *
621
     * @return string
622
     */
623
    public function getReturnUrlSuccess()
624
    {
625
        return $this->returnUrlSuccess;
626
    }
627
628
    /**
629
     * Set the return success URL.
630
     *
631
     * @param string $returnUrlSuccess The URL.
632
     * @return $this
633 6
     */
634
    public function setReturnUrlSuccess($returnUrlSuccess)
635 6
    {
636
        $this->returnUrlSuccess = $returnUrlSuccess;
637 6
638
        return $this;
639
    }
640
641
    /**
642
     * Get the return cancel URL.
643
     *
644
     * @return string
645
     */
646
    public function getReturnUrlCancel()
647
    {
648
        return $this->returnUrlCancel;
649
    }
650
651
    /**
652
     * Set the return cancel URL.
653
     *
654
     * @param string $returnUrlCancel The URL.
655
     * @return $this
656 6
     */
657
    public function setReturnUrlCancel($returnUrlCancel)
658 6
    {
659
        $this->returnUrlCancel = $returnUrlCancel;
660 6
661
        return $this;
662
    }
663
664
    /**
665
     * Get the checkout URL.
666
     *
667
     * @return string
668 3
     */
669
    public function getCheckoutUrl()
670 3
    {
671
        return $this->checkoutUrl;
672
    }
673
674
    /**
675
     * Set the checkout URL.
676
     *
677
     * @param string $checkoutUrl The URL.
678
     * @return $this
679 6
     */
680
    public function setCheckoutUrl($checkoutUrl)
681 6
    {
682
        $this->checkoutUrl = $checkoutUrl;
683 6
684
        return $this;
685
    }
686
687
    /**
688
     * Get the features.
689
     *
690
     * @return array
691
     */
692
    public function getFeatures()
693
    {
694
        return $this->features;
695
    }
696
697
    /**
698
     * Set the features.
699
     *
700
     * @param Feature[] $features The features.
701
     * @return $this
702
     */
703
    public function setFeatures(array $features)
704
    {
705
        $this->features = $features;
706
707
        return $this;
708
    }
709
710
    /**
711
     * Add a feature.
712
     *
713
     * @param Feature $feature The feature to add.
714 6
     */
715
    public function addFeature(Feature $feature)
716 6
    {
717 6
        $this->features[] = $feature;
718
    }
719
}
720