Passed
Pull Request — master (#103)
by Razvan
15:39 queued 12:47
created

Pass::setLabelColor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Passbook package.
5
 *
6
 * (c) Eymen Gunay <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Passbook;
13
14
use DateTime;
15
use Passbook\Pass\BarcodeInterface;
16
use Passbook\Pass\BeaconInterface;
17
use Passbook\Pass\NfcInterface;
18
use Passbook\Pass\ImageInterface;
19
use Passbook\Pass\LocalizationInterface;
20
use Passbook\Pass\LocationInterface;
21
use Passbook\Pass\Structure;
22
use Passbook\Pass\StructureInterface;
23
24
/**
25
 * Pass
26
 *
27
 * @author Eymen Gunay <[email protected]>
28
 * @author Sotaro Omura <http://omoon.org>
29
 * @author Dzamir <https://github.com/Dzamir>
30
 */
31
class Pass implements PassInterface
32
{
33
    /**
34
     * Serial number that uniquely identifies the pass.
35
     * No two passes with the same pass type identifier
36
     * may have the same serial number.
37
     *
38
     * @var string
39
     */
40
    protected $serialNumber;
41
42
    /**
43
     * Brief description of the pass,
44
     * used by the iOS accessibility technologies.
45
     *
46
     * @var string
47
     */
48
    protected $description;
49
50
    /**
51
     * Version of the file format.
52
     * The value must be 1.
53
     *
54
     * @var int
55
     */
56
    protected $formatVersion = 1;
57
58
    /**
59
     * Pass type
60
     *
61
     * @var string
62
     */
63
    protected $type;
64
65
    /**
66
     * Pass structure
67
     *
68
     * @var Structure
69
     */
70
    protected $structure;
71
72
    /**
73
     * Pass images
74
     *
75
     * @var ImageInterface[]
76
     */
77
    protected $images = array();
78
79
    /**
80
     * Beacons where the pass is relevant.
81
     *
82
     * @var array
83
     */
84
    protected $beacons = [];
85
86
    /**
87
     * NFC where the pass is relevant.
88
     *
89
     * @var array
90
     */
91
    protected $nfc = [];
92
93
94
    /**
95
     * A list of iTunes Store item identifiers (also known as Adam IDs) for the
96
     * associated apps.
97
     *
98
     * Only one item in the list is used—the first item identifier for an app
99
     * compatible with the current device. If the app is not installed, the
100
     * link opens the App Store and shows the app. If the app is already
101
     * installed, the link launches the app.
102
     *
103
     * @var int[]
104
     */
105
    protected $associatedStoreIdentifiers = [];
106
107
    /**
108
     * Locations where the pass is relevant.
109
     * For example, the location of your store.
110
     *
111
     * @var array
112
     */
113
    protected $locations = [];
114
115
    /**
116
     * List of localizations
117
     *
118
     * @var LocalizationInterface[]
119
     */
120
    protected $localizations = [];
121
122
    /**
123
     * Date and time when the pass becomes relevant.
124
     * For example, the start time of a movie.
125
     *
126
     * @var DateTime
127
     */
128
    protected $relevantDate;
129
130
    /**
131
     * Maximum distance in meters from a relevant latitude and longitude that
132
     * the pass is relevant. This number is compared to the pass’s default
133
     * distance and the smaller value is used.
134
     * Available in iOS 7.0.
135
     * @var int
136
     */
137
    protected $maxDistance;
138
139
    /**
140
     * Barcodes available to be displayed of iOS 9 and later. The system uses
141
     * the first valid barcode in the array.
142
     * @var BarcodeInterface[]
143
     */
144
    protected $barcodes = [];
145
146
    /**
147
     * Barcode to be displayed for iOS 8 and earlier.
148
     * @var BarcodeInterface
149
     */
150
    protected $barcode;
151
152
    /**
153
     * Background color of the pass, specified as an CSS-style RGB triple.
154
     *
155
     * @var string rgb(23, 187, 82)
156
     */
157
    protected $backgroundColor;
158
159
    /**
160
     * Foreground color of the pass, specified as a CSS-style RGB triple.
161
     *
162
     * @var string rgb(100, 10, 110)
163
     */
164
    protected $foregroundColor;
165
166
    /**
167
     * Identifier used to group related passes.
168
     * If a grouping identifier is specified, passes with the same style, pass type identifier,
169
     * and grouping identifier are displayed as a group. Otherwise, passes are grouped automatically.
170
     *
171
     * @var string
172
     */
173
    protected $groupingIdentifier;
174
175
    /**
176
     * Color of the label text, specified as a CSS-style RGB triple.
177
     *
178
     * @var string rgb(255, 255, 255)
179
     */
180
    protected $labelColor;
181
182
    /**
183
     * Text displayed next to the logo on the pass.
184
     *
185
     * @var string
186
     */
187
    protected $logoText;
188
189
190
191
    /**
192
     * If true, the strip image is displayed without a shine effect.
193
     *
194
     * @var string The default value is false
195
     */
196
    protected $suppressStripShine;
197
198
    /**
199
     * The authentication token to use with the web service.
200
     * The token must be 16 characters or longer.
201
     *
202
     * @var string
203
     */
204
    protected $authenticationToken;
205
206
    /**
207
     * The URL of a web service that conforms to the API described in Passbook Web Service Reference.
208
     * http://developer.apple.com/library/ios/documentation/PassKit/Reference/PassKit_WebService/WebService.html#//apple_ref/doc/uid/TP40011988
209
     *
210
     * @var string
211
     */
212
    protected $webServiceURL;
213
214
    /**
215
     * Pass type identifier
216
     *
217
     * @var string
218
     */
219
    protected $passTypeIdentifier;
220
221
    /**
222
     * Team identifier
223
     *
224
     * @var string
225
     */
226
    protected $teamIdentifier;
227
228
    /**
229
     * Organization name
230
     *
231
     * @var string
232
     */
233
    protected $organizationName;
234
235
    /**
236
     * Date and time when the pass expires.
237
     *
238
     * @var DateTime
239
     */
240
    protected $expirationDate;
241
242
    /**
243
     * Indicates that the pass is void—for example, a one time use coupon that has been redeemed. The default value is
244
     * false.
245
     *
246
     * @var boolean
247
     */
248
    protected $voided;
249
250
    /**
251
     *
252
     * A URL to be passed to the associated app when launching it.
253
     * The app receives this URL in the application:didFinishLaunchingWithOptions: and application:handleOpenURL:
254
     * methods of its app delegate. If this key is present, the associatedStoreIdentifiers key must also be present.
255
     *
256
     * @var string
257
     */
258
    protected $appLaunchURL;
259
260
	/**
261
	 * Pass userInfo
262
	 *
263
	 * @var mixed
264
	 */
265
	protected $userInfo;
266
267
    /**
268
     *
269
     * Flag to decide if the pass can be shared or not.
270
     *
271
     * @var bool
272
     *
273
     */
274
	protected bool $sharingProhibited = false;
275
276 29
    public function __construct($serialNumber, $description)
277
    {
278
        // Required
279 29
        $this->setSerialNumber($serialNumber);
280 29
        $this->setDescription($description);
281
    }
282
283 10
    public function toArray()
284
    {
285 10
        $array = [];
286
287
        // Structure
288 10
        if ($this->getStructure()) {
289 5
            $array[$this->getType()] = $this->getStructure()->toArray();
290
        }
291
292 10
        $properties = array(
293 10
            'serialNumber',
294 10
            'description',
295 10
            'formatVersion',
296 10
            'beacons',
297 10
            'nfc',
298 10
            'locations',
299 10
            'maxDistance',
300 10
            'relevantDate',
301 10
            'barcode',
302 10
            'barcodes',
303 10
            'backgroundColor',
304 10
            'foregroundColor',
305 10
            'groupingIdentifier',
306 10
            'labelColor',
307 10
            'logoText',
308 10
            'suppressStripShine',
309 10
            'authenticationToken',
310 10
            'webServiceURL',
311 10
            'passTypeIdentifier',
312 10
            'teamIdentifier',
313 10
            'organizationName',
314 10
            'expirationDate',
315 10
            'voided',
316 10
            'appLaunchURL',
317 10
            'associatedStoreIdentifiers',
318 10
	        'userInfo',
319 10
            'sharingProhibited'
320 10
        );
321 10
        foreach ($properties as $property) {
322 10
            $method = 'is' . ucfirst($property);
323 10
            if (!method_exists($this, $method)) {
324 10
                $method = 'get' . ucfirst($property);
325
            }
326 10
            $val = $this->$method();
327 10
            if ($val instanceof DateTime) {
328
                // Date
329 2
                $array[$property] = $val->format('c');
330 10
            } elseif (is_object($val)) {
331
                // Object
332
                /* @var ArrayableInterface $val */
333 3
                $array[$property] = $val->toArray();
334 10
            } elseif (is_scalar($val)) {
335
                // Scalar
336 10
                $array[$property] = $val;
337 10
            } elseif (is_array($val)) {
338
                // Array
339 10
                foreach ($val as $k => $v) {
340 5
                    if (is_object($v)) {
341
                        /* @var ArrayableInterface $v */
342 4
                        $array[$property][$k] = $v->toArray();
343
                    } else {
344 1
                        $array[$property][$k] = $v;
345
                    }
346
                }
347
            }
348
        }
349 10
        if ($this->getAssociatedStoreIdentifiers()) {
350 1
            $array['associatedStoreIdentifiers'] = $this->getAssociatedStoreIdentifiers();
351
        }
352
353 10
        return $array;
354
    }
355
356
    /**
357
     * {@inheritdoc}
358
     */
359 29
    public function setSerialNumber($serialNumber)
360
    {
361 29
        $this->serialNumber = strval($serialNumber);
362
363 29
        return $this;
364
    }
365
366
    /**
367
     * {@inheritdoc}
368
     */
369 27
    public function getSerialNumber()
370
    {
371 27
        return $this->serialNumber;
372
    }
373
374
    /**
375
     * {@inheritdoc}
376
     */
377 29
    public function setDescription($description)
378
    {
379 29
        $this->description = $description;
380
381 29
        return $this;
382
    }
383
384
    /**
385
     * {@inheritdoc}
386
     */
387 26
    public function getDescription()
388
    {
389 26
        return $this->description;
390
    }
391
392
    /**
393
     * {@inheritdoc}
394
     */
395 26
    public function getFormatVersion()
396
    {
397 26
        return $this->formatVersion;
398
    }
399
400
    /**
401
     * {@inheritdoc}
402
     */
403 2
    public function setFormatVersion($formatVersion)
404
    {
405 2
        $this->formatVersion = $formatVersion;
406
407 2
        return $this;
408
    }
409
410
    /**
411
     * {@inheritdoc}
412
     */
413 6
    public function getType()
414
    {
415 6
        return $this->type;
416
    }
417
418
    /**
419
     * {@inheritdoc}
420
     */
421 2
    public function setType($type)
422
    {
423 2
        $this->type = $type;
424
425 2
        return $this;
426
    }
427
428
    /**
429
     * {@inheritdoc}
430
     */
431 5
    public function setStructure(StructureInterface $structure)
432
    {
433 5
        $this->structure = $structure;
0 ignored issues
show
Documentation Bug introduced by
$structure is of type Passbook\Pass\StructureInterface, but the property $structure was declared to be of type Passbook\Pass\Structure. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
434
435 5
        return $this;
436
    }
437
438
    /**
439
     * {@inheritdoc}
440
     */
441 10
    public function getStructure()
442
    {
443 10
        return $this->structure;
444
    }
445
446
    /**
447
     * {@inheritdoc}
448
     */
449 5
    public function addImage(ImageInterface $image)
450
    {
451 5
        $this->images[] = $image;
452
453 5
        return $this;
454
    }
455
456
    /**
457
     * {@inheritdoc}
458
     */
459 19
    public function getImages()
460
    {
461 19
        return $this->images;
462
    }
463
464
    /**
465
     * {@inheritdoc}
466
     */
467 1
    public function addLocalization(LocalizationInterface $localization)
468
    {
469 1
        $this->localizations[] = $localization;
470
471 1
        return $this;
472
    }
473
474
    /**
475
     * {@inheritdoc}
476
     */
477 3
    public function getLocalizations()
478
    {
479 3
        return $this->localizations;
480
    }
481
482
    /**
483
     * {@inheritdoc}
484
     */
485 2
    public function addAssociatedStoreIdentifier($associatedStoreIdentifier)
486
    {
487 2
        $this->associatedStoreIdentifiers[] = $associatedStoreIdentifier;
488
489 2
        return $this;
490
    }
491
492
    /**
493
     * {@inheritdoc}
494
     */
495 26
    public function getAssociatedStoreIdentifiers()
496
    {
497 26
        return $this->associatedStoreIdentifiers;
498
    }
499
500
    /**
501
     * {@inheritdoc}
502
     */
503 3
    public function addLocation(LocationInterface $location)
504
    {
505 3
        $this->locations[] = $location;
506
507 3
        return $this;
508
    }
509
510
    /**
511
     * {@inheritdoc}
512
     */
513 26
    public function getLocations()
514
    {
515 26
        return $this->locations;
516
    }
517
518
    /**
519
     * {@inheritdoc}
520
     */
521 2
    public function addBeacon(BeaconInterface $beacon)
522
    {
523 2
        $this->beacons[] = $beacon;
524
525 2
        return $this;
526
    }
527
528
    /**
529
     * {@inheritdoc}
530
     */
531 26
    public function getBeacons()
532
    {
533 26
        return $this->beacons;
534
    }
535
536
    /**
537
     * {@inheritdoc}
538
     */
539
    public function addNfc(NfcInterface $nfc)
540
    {
541
        $this->nfc[] = $nfc;
542
        return $this;
543
    }
544
545
    /**
546
     * {@inheritdoc}
547
     */
548 26
    public function getNfc()
549
    {
550 26
        return $this->nfc;
551
    }
552
553
554
    /**
555
     * {@inheritdoc}
556
     */
557 2
    public function setRelevantDate(DateTime $relevantDate)
558
    {
559 2
        $this->relevantDate = $relevantDate;
560
561 2
        return $this;
562
    }
563
564
    /**
565
     * {@inheritdoc}
566
     */
567 10
    public function getRelevantDate()
568
    {
569 10
        return $this->relevantDate;
570
    }
571
572
    /**
573
     * {@inheritdoc}
574
     */
575 1
    public function setMaxDistance($maxDistance)
576
    {
577 1
        $this->maxDistance = $maxDistance;
578
579 1
        return $this;
580
    }
581
582
    /**
583
     * {@inheritdoc}
584
     */
585 11
    public function getMaxDistance()
586
    {
587 11
        return $this->maxDistance;
588
    }
589
590
    /**
591
     * {@inheritdoc}
592
     */
593 6
    public function setBarcode(BarcodeInterface $barcode)
594
    {
595 6
        $this->barcode = $barcode;
596 6
        array_unshift($this->barcodes, $barcode);
597
598 6
        return $this;
599
    }
600
601
    /**
602
     * {@inheritdoc}
603
     */
604
    public function setNfc(NfcInterface $nfc)
605
    {
606
        $this->nfc = $nfc;
0 ignored issues
show
Documentation Bug introduced by
It seems like $nfc of type Passbook\Pass\NfcInterface is incompatible with the declared type array of property $nfc.

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...
607
        return $this;
608
    }
609
610
611
    /**
612
     * {@inheritdoc}
613
     */
614 27
    public function getBarcode()
615
    {
616 27
        return $this->barcode;
617
    }
618
619
    /**
620
     * {@inheritdoc}
621
     */
622 1
    public function addBarcode(BarcodeInterface $barcode)
623
    {
624 1
        $this->barcodes[] = $barcode;
625
626 1
        if (empty($this->barcode)) {
627 1
            $this->barcode = $barcode;
628
        }
629
630 1
        return $this;
631
    }
632
633
    /**
634
     * {@inheritdoc}
635
     */
636 11
    public function getBarcodes()
637
    {
638 11
        return $this->barcodes;
639
    }
640
641
    /**
642
     * {@inheritdoc}
643
     */
644 5
    public function setBackgroundColor($backgroundColor)
645
    {
646 5
        $this->backgroundColor = $backgroundColor;
647
648 5
        return $this;
649
    }
650
651
    /**
652
     * {@inheritdoc}
653
     */
654 10
    public function getBackgroundColor()
655
    {
656 10
        return $this->backgroundColor;
657
    }
658
659
    /**
660
     * {@inheritdoc}
661
     */
662 2
    public function setForegroundColor($foregroundColor)
663
    {
664 2
        $this->foregroundColor = $foregroundColor;
665
666 2
        return $this;
667
    }
668
669
    /**
670
     * {@inheritdoc}
671
     */
672 10
    public function getForegroundColor()
673
    {
674 10
        return $this->foregroundColor;
675
    }
676
677
    /**
678
     * {@inheritdoc}
679
     */
680 3
    public function setGroupingIdentifier($groupingIdentifier)
681
    {
682 3
        $this->groupingIdentifier = $groupingIdentifier;
683
684 3
        return $this;
685
    }
686
687
    /**
688
     * {@inheritdoc}
689
     */
690 26
    public function getGroupingIdentifier()
691
    {
692 26
        return $this->groupingIdentifier;
693
    }
694
695
    /**
696
     * {@inheritdoc}
697
     */
698 1
    public function setLabelColor($labelColor)
699
    {
700 1
        $this->labelColor = $labelColor;
701
702 1
        return $this;
703
    }
704
705
    /**
706
     * {@inheritdoc}
707
     */
708 10
    public function getLabelColor()
709
    {
710 10
        return $this->labelColor;
711
    }
712
713
    /**
714
     * {@inheritdoc}
715
     */
716 4
    public function setLogoText($logoText)
717
    {
718 4
        $this->logoText = $logoText;
719
720 4
        return $this;
721
    }
722
723
    /**
724
     * {@inheritdoc}
725
     */
726 10
    public function getLogoText()
727
    {
728 10
        return $this->logoText;
729
    }
730
731
    /**
732
     * {@inheritdoc}
733
     */
734 1
    public function setSuppressStripShine($suppressStripShine)
735
    {
736 1
        $this->suppressStripShine = $suppressStripShine;
737
738 1
        return $this;
739
    }
740
741
    /**
742
     * {@inheritdoc}
743
     */
744 10
    public function getSuppressStripShine()
745
    {
746 10
        return $this->suppressStripShine;
747
    }
748
749
    /**
750
     * {@inheritdoc}
751
     */
752 2
    public function setAuthenticationToken($authenticationToken)
753
    {
754 2
        $this->authenticationToken = $authenticationToken;
755
756 2
        return $this;
757
    }
758
759
    /**
760
     * {@inheritdoc}
761
     */
762 11
    public function getAuthenticationToken()
763
    {
764 11
        return (string) $this->authenticationToken;
765
    }
766
767
    /**
768
     * {@inheritdoc}
769
     */
770 2
    public function setWebServiceURL($webServiceURL)
771
    {
772 2
        $this->webServiceURL = $webServiceURL;
773
774 2
        return $this;
775
    }
776
777
    /**
778
     * {@inheritdoc}
779
     */
780 26
    public function getWebServiceURL()
781
    {
782 26
        return $this->webServiceURL;
783
    }
784
785
    /**
786
     * {@inheritdoc}
787
     */
788 5
    public function setPassTypeIdentifier($passTypeIdentifier)
789
    {
790 5
        $this->passTypeIdentifier = $passTypeIdentifier;
791
792 5
        return $this;
793
    }
794
795
    /**
796
     * {@inheritdoc}
797
     */
798 26
    public function getPassTypeIdentifier()
799
    {
800 26
        return $this->passTypeIdentifier;
801
    }
802
803
    /**
804
     * {@inheritdoc}
805
     */
806 5
    public function setTeamIdentifier($teamIdentifier)
807
    {
808 5
        $this->teamIdentifier = $teamIdentifier;
809
810 5
        return $this;
811
    }
812
813
    /**
814
     * {@inheritdoc}
815
     */
816 26
    public function getTeamIdentifier()
817
    {
818 26
        return $this->teamIdentifier;
819
    }
820
821
    /**
822
     * {@inheritdoc}
823
     */
824 5
    public function setOrganizationName($organizationName)
825
    {
826 5
        $this->organizationName = $organizationName;
827
828 5
        return $this;
829
    }
830
831
    /**
832
     * {@inheritdoc}
833
     */
834 26
    public function getOrganizationName()
835
    {
836 26
        return $this->organizationName;
837
    }
838
839
    /**
840
     * {@inheritdoc}
841
     */
842
    public function setExpirationDate(DateTime $expirationDate)
843
    {
844
        $this->expirationDate = $expirationDate;
845
846
        return $this;
847
    }
848
849
    /**
850
     * {@inheritdoc}
851
     */
852 10
    public function getExpirationDate()
853
    {
854 10
        return $this->expirationDate;
855
    }
856
857
    /**
858
     * {@inheritdoc}
859
     */
860
    public function setVoided($voided)
861
    {
862
        $this->voided = $voided;
863
864
        return $this;
865
    }
866
867
    /**
868
     * {@inheritdoc}
869
     */
870 10
    public function getVoided()
871
    {
872 10
        return $this->voided;
873
    }
874
875
    /**
876
     * {@inheritdoc}
877
     */
878 2
    public function setAppLaunchURL($appLaunchURL)
879
    {
880 2
        $this->appLaunchURL = $appLaunchURL;
881
882 2
        return $this;
883
    }
884
885
    /**
886
     * {@inheritdoc}
887
     */
888 26
    public function getAppLaunchURL()
889
    {
890 26
        return $this->appLaunchURL;
891
    }
892
893
	/**
894
	 * {@inheritdoc}
895
	 */
896
	public function setUserInfo($userInfo) {
897
		$this->userInfo = $userInfo;
898
899
		return $this;
900
	}
901
902
	/**
903
	 * {@inheritdoc}
904
	 */
905 10
	public function getUserInfo() {
906 10
		return $this->userInfo;
907
	}
908
909
	public function setSharingProhibited(bool $value): self
910
    {
911
	    $this->sharingProhibited = $value;
912
913
	    return $this;
914
    }
915
916 10
    public function getSharingProhibited(): bool {
917 10
	    return $this->sharingProhibited;
918
    }
919
920
}
921