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.
Completed
Pull Request — master (#3)
by
unknown
10:45
created

ArticleTrait   B

Complexity

Total Complexity 47

Size/Duplication

Total Lines 741
Duplicated Lines 1.21 %

Coupling/Cohesion

Components 5
Dependencies 0

Test Coverage

Coverage 61.26%

Importance

Changes 0
Metric Value
wmc 47
lcom 5
cbo 0
dl 9
loc 741
ccs 68
cts 111
cp 0.6126
rs 8
c 0
b 0
f 0

45 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
A getAssignedArticles() 0 6 1
A setAssignedArticles() 0 6 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
     * Assigned Articles of an Addon-Article.
224
     *
225
     * @var string
226
     *
227 9
     * @JMS\Type("string")
228
     * @JMS\SerializedName("ASSIGNED_ARTICLES")
229 9
     */
230
    protected $assignedArticles;
231
232
    /**
233
     * Get the article number.
234
     *
235
     * @return integer
236
     */
237
    public function getArticleNumber()
238 12
    {
239
        return $this->articleNumber;
240 12
    }
241
242 12
    /**
243
     * Set the article number.
244
     *
245
     * @param string $articleNumber The article number.
246
     * @return $this
247
     */
248
    public function setArticleNumber($articleNumber)
249
    {
250
        $this->articleNumber = $articleNumber;
251
252
        return $this;
253
    }
254
255
    /**
256
     * Get the title.
257
     *
258
     * @return string
259
     */
260
    public function getTitle()
261 6
    {
262
        return $this->title;
263 6
    }
264
265 6
    /**
266
     * Set the title.
267
     *
268
     * @param string $title The title.
269
     * @return $this
270
     */
271
    public function setTitle($title)
272
    {
273
        $this->title = $title;
274
275
        return $this;
276
    }
277
278
    /**
279
     * Get the description.
280
     *
281
     * @return string
282
     */
283
    public function getDescription()
284 6
    {
285
        return $this->description;
286 6
    }
287
288 6
    /**
289
     * Set the description.
290
     *
291
     * @param string $description The description.
292
     * @return $this
293
     */
294
    public function setDescription($description)
295
    {
296
        $this->description = $description;
297
298
        return $this;
299
    }
300
301
    /**
302
     * Get the tags.
303
     *
304
     * @return array
305
     */
306
    public function getTags()
307
    {
308
        $tags = explode(',', $this->tags);
309 6
310
        return array_map('trim', $tags);
311 6
    }
312
313 6
    /**
314
     * Set the tags.
315
     * #
316
     * @param array $tags The tags to set.
317
     * @return $this
318
     */
319
    public function setTags(array $tags)
320
    {
321
        $this->tags = implode(', ', $tags);
322
323
        return $this;
324
    }
325
326
    /**
327
     * Get the unit price.
328
     *
329
     * @return float
330
     */
331
    public function getUnitPrice()
332 6
    {
333
        return $this->unitPrice;
334 6
    }
335
336 6
    /**
337
     * Set the unit price.
338
     *
339
     * @param float $unitPrice The price.
340
     * @return $this
341
     */
342
    public function setUnitPrice($unitPrice)
343
    {
344
        $this->unitPrice = $unitPrice;
345
346
        return $this;
347
    }
348
349
    /**
350
     * Get the setup fee.
351
     *
352
     * @return float
353
     */
354
    public function getSetupFee()
355 6
    {
356
        return $this->setupFee;
357 6
    }
358
359 6
    /**
360
     * Set the setup fee.
361
     *
362
     * @param float $setupFee The setup fee.
363
     * @return $this
364
     */
365
    public function setSetupFee($setupFee)
366
    {
367
        $this->setupFee = $setupFee;
368
369
        return $this;
370
    }
371
372
    /**
373
     * Check if it allows multiple instances.
374
     *
375
     * @return boolean
376
     */
377
    public function allowsMultiple()
378 6
    {
379
        return (boolean)$this->allowMultiple;
380 6
    }
381
382 6
    /**
383
     * Set if it allows multiple instances.
384
     *
385
     * @param boolean $allowMultiple The flag.
386
     * @return $this
387
     */
388
    public function setAllowMultiple($allowMultiple)
389
    {
390
        $this->allowMultiple = (integer)(boolean)$allowMultiple;
391
392
        return $this;
393
    }
394
395
    /**
396
     * Check if the article is an addon.
397
     *
398
     * @return boolean
399
     */
400
    public function isAddon()
401 6
    {
402
        return (boolean)$this->isAddon;
403 6
    }
404
405 6
    /**
406
     * Set that the article is an addon.
407
     *
408
     * @param boolean $isAddon Flag if the article is an addon.
409
     * @return $this
410
     */
411
    public function setIsAddon($isAddon)
412
    {
413
        $this->isAddon = (integer)(boolean)$isAddon;
414
415
        return $this;
416
    }
417
418
    /**
419
     * Get the translation.
420
     *
421
     * @return Translation
422
     */
423
    public function getTranslation()
424 6
    {
425
        return $this->translation;
426 6
    }
427
428 6
    /**
429
     * Set the translation.
430
     *
431
     * @param Translation $translation The translation to set.
432
     * @return $this
433
     */
434
    public function setTranslation(Translation $translation)
435
    {
436
        $this->translation = $translation;
437
438
        return $this;
439
    }
440
441
    /**
442
     * Get the currency code.
443
     *
444
     * @return string
445
     */
446
    public function getCurrencyCode()
447 6
    {
448
        return $this->currencyCode;
449 6
    }
450
451 6
    /**
452
     * Set the currency code.
453
     *
454
     * @param string $currencyCode The currency code.
455
     * @return $this
456
     */
457
    public function setCurrencyCode($currencyCode)
458
    {
459
        $this->currencyCode = $currencyCode;
460
461
        return $this;
462
    }
463
464
    /**
465
     * Get the VAT percentage.
466
     *
467
     * @return float
468
     */
469
    public function getVatPercent()
470 6
    {
471
        return $this->vatPercent;
472 6
    }
473
474
    /**
475 6
     * Set the VAT percentage.
476
     *
477 6
     * @param float $vatPercent The VAT percentage.
478
     * @return $this
479
     * @throws \InvalidArgumentException If the percent is not between 0 and 100
480
     */
481 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...
482
    {
483
        if ($vatPercent < 0 || $vatPercent > 100) {
484
            throw new \InvalidArgumentException('VAT percentage must be between 0-100');
485
        }
486
        $this->vatPercent = $vatPercent;
487
488
        return $this;
489
    }
490
491
    /**
492
     * Get the subscription interval.
493
     *
494
     * @return string
495
     */
496 6
    public function getSubscriptionInterval()
497
    {
498 6
        return $this->subscriptionInterval;
499
    }
500 6
501
    /**
502
     * Set the subscription interval.
503
     *
504
     * @param string $subscriptionInterval The interval.
505
     * @return $this
506
     */
507
    public function setSubscriptionInterval($subscriptionInterval)
508
    {
509
        $this->subscriptionInterval = $subscriptionInterval;
510
511
        return $this;
512
    }
513
514
    /**
515
     * Get the subscription number of events.
516
     *
517
     * @return integer
518
     */
519 6
    public function getSubscriptionNumberEvents()
520
    {
521 6
        return $this->subscriptionNumberEvents;
522
    }
523 6
524
    /**
525
     * Set the subscription number of events.
526
     *
527
     * @param integer $subscriptionNumberEvents The number of events.
528
     * @return $this
529
     */
530
    public function setSubscriptionNumberEvents($subscriptionNumberEvents)
531
    {
532
        $this->subscriptionNumberEvents = $subscriptionNumberEvents;
533
534
        return $this;
535
    }
536
537
    /**
538
     * Get the subscription trial.
539
     *
540
     * @return string
541
     */
542 6
    public function getSubscriptionTrial()
543
    {
544 6
        return $this->subscriptionTrial;
545
    }
546 6
547
    /**
548
     * Set the subscription trial.
549
     *
550
     * @param string $subscriptionTrial The subscription trial.
551
     * @return $this
552
     */
553
    public function setSubscriptionTrial($subscriptionTrial)
554
    {
555
        $this->subscriptionTrial = $subscriptionTrial;
556
557
        return $this;
558
    }
559
560
    /**
561
     * Get the subscription duration.
562
     *
563
     * @return string
564
     */
565 6
    public function getSubscriptionDuration()
566
    {
567 6
        return $this->subscriptionDuration;
568
    }
569 6
570
    /**
571
     * Set the subscription duration.
572
     *
573
     * @param string $subscriptionDuration The duration.
574
     * @return $this
575
     */
576
    public function setSubscriptionDuration($subscriptionDuration)
577
    {
578
        $this->subscriptionDuration = $subscriptionDuration;
579
580
        return $this;
581
    }
582
583
    /**
584
     * Get the subscription duration follow.
585
     *
586
     * @return string
587
     */
588 6
    public function getSubscriptionDurationFollow()
589
    {
590 6
        return $this->subscriptionDurationFollow;
591
    }
592 6
593
    /**
594
     * Set the subscription duration follow.
595
     *
596
     * @param string $subscriptionDurationFollow The duration follow.
597
     * @return $this
598
     */
599
    public function setSubscriptionDurationFollow($subscriptionDurationFollow)
600
    {
601
        $this->subscriptionDurationFollow = $subscriptionDurationFollow;
602
603
        return $this;
604
    }
605
606
    /**
607
     * Get the subscription cancellation period.
608
     * @return string
609
     */
610 6
    public function getSubscriptionCancellationPeriod()
611
    {
612 6
        return $this->subscriptionCancellationPeriod;
613
    }
614 6
615
    /**
616
     * Set the subscription cancellation period.
617
     *
618
     * @param string $subscriptionCancellationPeriod The period.
619
     * @return $this
620
     */
621
    public function setSubscriptionCancellationPeriod($subscriptionCancellationPeriod)
622
    {
623
        $this->subscriptionCancellationPeriod = $subscriptionCancellationPeriod;
624
625
        return $this;
626
    }
627
628
    /**
629
     * Get the success return URL.
630
     *
631
     * @return string
632
     */
633 6
    public function getReturnUrlSuccess()
634
    {
635 6
        return $this->returnUrlSuccess;
636
    }
637 6
638
    /**
639
     * Set the return success URL.
640
     *
641
     * @param string $returnUrlSuccess The URL.
642
     * @return $this
643
     */
644
    public function setReturnUrlSuccess($returnUrlSuccess)
645
    {
646
        $this->returnUrlSuccess = $returnUrlSuccess;
647
648
        return $this;
649
    }
650
651
    /**
652
     * Get the return cancel URL.
653
     *
654
     * @return string
655
     */
656 6
    public function getReturnUrlCancel()
657
    {
658 6
        return $this->returnUrlCancel;
659
    }
660 6
661
    /**
662
     * Set the return cancel URL.
663
     *
664
     * @param string $returnUrlCancel The URL.
665
     * @return $this
666
     */
667
    public function setReturnUrlCancel($returnUrlCancel)
668 3
    {
669
        $this->returnUrlCancel = $returnUrlCancel;
670 3
671
        return $this;
672
    }
673
674
    /**
675
     * Get the checkout URL.
676
     *
677
     * @return string
678
     */
679 6
    public function getCheckoutUrl()
680
    {
681 6
        return $this->checkoutUrl;
682
    }
683 6
684
    /**
685
     * Set the checkout URL.
686
     *
687
     * @param string $checkoutUrl The URL.
688
     * @return $this
689
     */
690
    public function setCheckoutUrl($checkoutUrl)
691
    {
692
        $this->checkoutUrl = $checkoutUrl;
693
694
        return $this;
695
    }
696
697
    /**
698
     * Get the features.
699
     *
700
     * @return array
701
     */
702
    public function getFeatures()
703
    {
704
        return $this->features;
705
    }
706
707
    /**
708
     * Set the features.
709
     *
710
     * @param Feature[] $features The features.
711
     * @return $this
712
     */
713
    public function setFeatures(array $features)
714 6
    {
715
        $this->features = $features;
716 6
717 6
        return $this;
718
    }
719
720
    /**
721
     * Add a feature.
722
     *
723
     * @param Feature $feature The feature to add.
724
     */
725
    public function addFeature(Feature $feature)
726
    {
727
        $this->features[] = $feature;
728
    }
729
730
    /**
731
     * @return array<int>
732
     */
733
    public function getAssignedArticles()
734
    {
735
        $articleIds = explode(',', $this->assignedArticles);
736
737
        return array_map('trim', $articleIds);
738
    }
739
740
    /**
741
     * @param array $assignedArticles
742
     * @return $this
743
     */
744
    public function setAssignedArticles(array $assignedArticles)
745
    {
746
        $this->assignedArticles = implode(', ', $assignedArticles);
747
748
        return $this;
749
    }
750
}
751