Passed
Pull Request — master (#106)
by
unknown
14:52
created

Pass::getStripColor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 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 StructureInterface
69
     */
70
    protected $structure;
71
72
    /**
73
     * Pass images
74
     *
75
     * @var ImageInterface[]
76
     */
77
    protected $images = [];
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 NfcInterface
90
     */
91
    protected $nfc;
92
93
    /**
94
     * A list of iTunes Store item identifiers (also known as Adam IDs) for the
95
     * associated apps.
96
     *
97
     * Only one item in the list is used—the first item identifier for an app
98
     * compatible with the current device. If the app is not installed, the
99
     * link opens the App Store and shows the app. If the app is already
100
     * installed, the link launches the app.
101
     *
102
     * @var int[]
103
     */
104
    protected $associatedStoreIdentifiers = [];
105
106
    /**
107
     * Locations where the pass is relevant.
108
     * For example, the location of your store.
109
     *
110
     * @var array
111
     */
112
    protected $locations = [];
113
114
    /**
115
     * List of localizations
116
     *
117
     * @var LocalizationInterface[]
118
     */
119
    protected $localizations = [];
120
121
    /**
122
     * Date and time when the pass becomes relevant.
123
     * For example, the start time of a movie.
124
     *
125
     * @var DateTime
126
     */
127
    protected $relevantDate;
128
129
    /**
130
     * Maximum distance in meters from a relevant latitude and longitude that
131
     * the pass is relevant. This number is compared to the pass’s default
132
     * distance and the smaller value is used.
133
     * Available in iOS 7.0.
134
     * @var int
135
     */
136
    protected $maxDistance;
137
138
    /**
139
     * Barcodes available to be displayed of iOS 9 and later. The system uses
140
     * the first valid barcode in the array.
141
     * @var BarcodeInterface[]
142
     */
143
    protected $barcodes = [];
144
145
    /**
146
     * Barcode to be displayed for iOS 8 and earlier.
147
     * @var BarcodeInterface
148
     */
149
    protected $barcode;
150
151
    /**
152
     * Background color of the pass, specified as an CSS-style RGB triple.
153
     *
154
     * @var string rgb(23, 187, 82)
155
     */
156
    protected $backgroundColor;
157
158
    /**
159
     * Foreground color of the pass, specified as a CSS-style RGB triple.
160
     *
161
     * @var string rgb(100, 10, 110)
162
     */
163
    protected $foregroundColor;
164
165
    /**
166
     * Identifier used to group related passes.
167
     * If a grouping identifier is specified, passes with the same style, pass type identifier,
168
     * and grouping identifier are displayed as a group. Otherwise, passes are grouped automatically.
169
     *
170
     * @var string
171
     */
172
    protected $groupingIdentifier;
173
174
    /**
175
     * Color of the label text, specified as a CSS-style RGB triple.
176
     *
177
     * @var string rgb(255, 255, 255)
178
     */
179
    protected $labelColor;
180
181
    /**
182
     * Color of the strip text if strip image is defined, specified as a CSS-style RGB triple.
183
     *
184
     * @var string rgb(255, 255, 255)
185
     */
186
    protected $stripColor;
187
188
    /**
189
     * Text displayed next to the logo on the pass.
190
     *
191
     * @var string
192
     */
193
    protected $logoText;
194
195
    /**
196
     * If true, the strip image is displayed without a shine effect.
197
     *
198
     * @var string The default value is false
199
     */
200
    protected $suppressStripShine;
201
202
    /**
203
     * The authentication token to use with the web service.
204
     * The token must be 16 characters or longer.
205
     *
206
     * @var string
207
     */
208
    protected $authenticationToken;
209
210
    /**
211
     * The URL of a web service that conforms to the API described in Passbook Web Service Reference.
212
     * http://developer.apple.com/library/ios/documentation/PassKit/Reference/PassKit_WebService/WebService.html#//apple_ref/doc/uid/TP40011988
213
     *
214
     * @var string
215
     */
216
    protected $webServiceURL;
217
218
    /**
219
     * Pass type identifier
220
     *
221
     * @var string
222
     */
223
    protected $passTypeIdentifier;
224
225
    /**
226
     * Team identifier
227
     *
228
     * @var string
229
     */
230
    protected $teamIdentifier;
231
232
    /**
233
     * Organization name
234
     *
235
     * @var string
236
     */
237
    protected $organizationName;
238
239
    /**
240
     * Date and time when the pass expires.
241
     *
242
     * @var DateTime
243
     */
244
    protected $expirationDate;
245
246
    /**
247
     * Indicates that the pass is void—for example, a one time use coupon that has been redeemed. The default value is
248
     * false.
249
     *
250
     * @var boolean
251
     */
252
    protected $voided;
253
254
    /**
255
     *
256
     * A URL to be passed to the associated app when launching it.
257
     * The app receives this URL in the application:didFinishLaunchingWithOptions: and application:handleOpenURL:
258
     * methods of its app delegate. If this key is present, the associatedStoreIdentifiers key must also be present.
259
     *
260
     * @var string
261
     */
262
    protected $appLaunchURL;
263
264
    /**
265
     * Pass userInfo
266
     *
267
     * @var mixed
268
     */
269
    protected $userInfo;
270
271
    /**
272
     *
273
     * Flag to decide if the pass can be shared or not.
274
     *
275
     * @var bool
276
     *
277
     */
278
    protected bool $sharingProhibited = false;
279
280 31
    public function __construct($serialNumber, $description)
281
    {
282
        // Required
283 31
        $this->setSerialNumber($serialNumber);
284 31
        $this->setDescription($description);
285
    }
286
287 12
    public function toArray()
288
    {
289 12
        $array = [];
290
291
        // Structure
292 12
        if ($this->getStructure()) {
293 5
            $array[$this->getType()] = $this->getStructure()->toArray();
294
        }
295
296 12
        $properties = [
297 12
            'serialNumber',
298 12
            'description',
299 12
            'formatVersion',
300 12
            'beacons',
301 12
            'nfc',
302 12
            'locations',
303 12
            'maxDistance',
304 12
            'relevantDate',
305 12
            'barcode',
306 12
            'barcodes',
307 12
            'backgroundColor',
308 12
            'foregroundColor',
309 12
            'groupingIdentifier',
310 12
            'labelColor',
311 12
            'stripColor',
312 12
            'logoText',
313 12
            'suppressStripShine',
314 12
            'authenticationToken',
315 12
            'webServiceURL',
316 12
            'passTypeIdentifier',
317 12
            'teamIdentifier',
318 12
            'organizationName',
319 12
            'expirationDate',
320 12
            'voided',
321 12
            'appLaunchURL',
322 12
            'associatedStoreIdentifiers',
323 12
            'userInfo',
324 12
            'sharingProhibited'
325 12
        ];
326 12
        foreach ($properties as $property) {
327 12
            $method = 'is' . ucfirst($property);
328 12
            if (!method_exists($this, $method)) {
329 12
                $method = 'get' . ucfirst($property);
330
            }
331 12
            $val = $this->$method();
332 12
            if ($val instanceof DateTime) {
333
                // Date
334 2
                $array[$property] = $val->format('c');
335 12
            } elseif (is_object($val)) {
336
                // Object
337
                /* @var ArrayableInterface $val */
338 4
                $array[$property] = $val->toArray();
339 12
            } elseif (is_scalar($val)) {
340
                // Scalar
341 12
                $array[$property] = $val;
342 12
            } elseif (is_array($val)) {
343
                // Array
344 12
                foreach ($val as $k => $v) {
345 5
                    if (is_object($v)) {
346
                        /* @var ArrayableInterface $v */
347 4
                        $array[$property][$k] = $v->toArray();
348
                    } else {
349 1
                        $array[$property][$k] = $v;
350
                    }
351
                }
352
            }
353
        }
354 12
        if ($this->getAssociatedStoreIdentifiers()) {
355 1
            $array['associatedStoreIdentifiers'] = $this->getAssociatedStoreIdentifiers();
356
        }
357
358 12
        return $array;
359
    }
360
361
    /**
362
     * {@inheritdoc}
363
     */
364 31
    public function setSerialNumber($serialNumber)
365
    {
366 31
        $this->serialNumber = strval($serialNumber);
367
368 31
        return $this;
369
    }
370
371
    /**
372
     * {@inheritdoc}
373
     */
374 29
    public function getSerialNumber()
375
    {
376 29
        return $this->serialNumber;
377
    }
378
379
    /**
380
     * {@inheritdoc}
381
     */
382 31
    public function setDescription($description)
383
    {
384 31
        $this->description = $description;
385
386 31
        return $this;
387
    }
388
389
    /**
390
     * {@inheritdoc}
391
     */
392 28
    public function getDescription()
393
    {
394 28
        return $this->description;
395
    }
396
397
    /**
398
     * {@inheritdoc}
399
     */
400 28
    public function getFormatVersion()
401
    {
402 28
        return $this->formatVersion;
403
    }
404
405
    /**
406
     * {@inheritdoc}
407
     */
408 2
    public function setFormatVersion($formatVersion)
409
    {
410 2
        $this->formatVersion = $formatVersion;
411
412 2
        return $this;
413
    }
414
415
    /**
416
     * {@inheritdoc}
417
     */
418 6
    public function getType()
419
    {
420 6
        return $this->type;
421
    }
422
423
    /**
424
     * {@inheritdoc}
425
     */
426 2
    public function setType($type)
427
    {
428 2
        $this->type = $type;
429
430 2
        return $this;
431
    }
432
433
    /**
434
     * {@inheritdoc}
435
     */
436 5
    public function setStructure(StructureInterface $structure)
437
    {
438 5
        $this->structure = $structure;
439
440 5
        return $this;
441
    }
442
443
    /**
444
     * {@inheritdoc}
445
     */
446 12
    public function getStructure()
447
    {
448 12
        return $this->structure;
449
    }
450
451
    /**
452
     * {@inheritdoc}
453
     */
454 5
    public function addImage(ImageInterface $image)
455
    {
456 5
        $this->images[] = $image;
457
458 5
        return $this;
459
    }
460
461
    /**
462
     * {@inheritdoc}
463
     */
464 19
    public function getImages()
465
    {
466 19
        return $this->images;
467
    }
468
469
    /**
470
     * {@inheritdoc}
471
     */
472 1
    public function addLocalization(LocalizationInterface $localization)
473
    {
474 1
        $this->localizations[] = $localization;
475
476 1
        return $this;
477
    }
478
479
    /**
480
     * {@inheritdoc}
481
     */
482 3
    public function getLocalizations()
483
    {
484 3
        return $this->localizations;
485
    }
486
487
    /**
488
     * {@inheritdoc}
489
     */
490 2
    public function addAssociatedStoreIdentifier($associatedStoreIdentifier)
491
    {
492 2
        $this->associatedStoreIdentifiers[] = $associatedStoreIdentifier;
493
494 2
        return $this;
495
    }
496
497
    /**
498
     * {@inheritdoc}
499
     */
500 28
    public function getAssociatedStoreIdentifiers()
501
    {
502 28
        return $this->associatedStoreIdentifiers;
503
    }
504
505
    /**
506
     * {@inheritdoc}
507
     */
508 3
    public function addLocation(LocationInterface $location)
509
    {
510 3
        $this->locations[] = $location;
511
512 3
        return $this;
513
    }
514
515
    /**
516
     * {@inheritdoc}
517
     */
518 28
    public function getLocations()
519
    {
520 28
        return $this->locations;
521
    }
522
523
    /**
524
     * {@inheritdoc}
525
     */
526 2
    public function addBeacon(BeaconInterface $beacon)
527
    {
528 2
        $this->beacons[] = $beacon;
529
530 2
        return $this;
531
    }
532
533
    /**
534
     * {@inheritdoc}
535
     */
536 28
    public function getBeacons()
537
    {
538 28
        return $this->beacons;
539
    }
540
541
    /**
542
     * {@inheritdoc}
543
     */
544 28
    public function getNfc()
545
    {
546 28
        return $this->nfc;
547
    }
548
549
    /**
550
     * {@inheritdoc}
551
     */
552 2
    public function setRelevantDate(DateTime $relevantDate)
553
    {
554 2
        $this->relevantDate = $relevantDate;
555
556 2
        return $this;
557
    }
558
559
    /**
560
     * {@inheritdoc}
561
     */
562 12
    public function getRelevantDate()
563
    {
564 12
        return $this->relevantDate;
565
    }
566
567
    /**
568
     * {@inheritdoc}
569
     */
570 1
    public function setMaxDistance($maxDistance)
571
    {
572 1
        $this->maxDistance = $maxDistance;
573
574 1
        return $this;
575
    }
576
577
    /**
578
     * {@inheritdoc}
579
     */
580 13
    public function getMaxDistance()
581
    {
582 13
        return $this->maxDistance;
583
    }
584
585
    /**
586
     * {@inheritdoc}
587
     */
588 6
    public function setBarcode(BarcodeInterface $barcode)
589
    {
590 6
        $this->barcode = $barcode;
591 6
        array_unshift($this->barcodes, $barcode);
592
593 6
        return $this;
594
    }
595
596
    /**
597
     * @param NfcInterface $nfc
598
     * @return $this
599
     */
600 1
    public function setNfc(NfcInterface $nfc)
601
    {
602 1
        $this->nfc = $nfc;
603
604 1
        return $this;
605
    }
606
607
    /**
608
     * {@inheritdoc}
609
     */
610 29
    public function getBarcode()
611
    {
612 29
        return $this->barcode;
613
    }
614
615
    /**
616
     * {@inheritdoc}
617
     */
618 1
    public function addBarcode(BarcodeInterface $barcode)
619
    {
620 1
        $this->barcodes[] = $barcode;
621
622 1
        if (empty($this->barcode)) {
623 1
            $this->barcode = $barcode;
624
        }
625
626 1
        return $this;
627
    }
628
629
    /**
630
     * {@inheritdoc}
631
     */
632 13
    public function getBarcodes()
633
    {
634 13
        return $this->barcodes;
635
    }
636
637
    /**
638
     * {@inheritdoc}
639
     */
640 5
    public function setBackgroundColor($backgroundColor)
641
    {
642 5
        $this->backgroundColor = $backgroundColor;
643
644 5
        return $this;
645
    }
646
647
    /**
648
     * {@inheritdoc}
649
     */
650 12
    public function getBackgroundColor()
651
    {
652 12
        return $this->backgroundColor;
653
    }
654
655
    /**
656
     * {@inheritdoc}
657
     */
658 2
    public function setForegroundColor($foregroundColor)
659
    {
660 2
        $this->foregroundColor = $foregroundColor;
661
662 2
        return $this;
663
    }
664
665
    /**
666
     * {@inheritdoc}
667
     */
668 12
    public function getForegroundColor()
669
    {
670 12
        return $this->foregroundColor;
671
    }
672
673
    /**
674
     * {@inheritdoc}
675
     */
676 3
    public function setGroupingIdentifier($groupingIdentifier)
677
    {
678 3
        $this->groupingIdentifier = $groupingIdentifier;
679
680 3
        return $this;
681
    }
682
683
    /**
684
     * {@inheritdoc}
685
     */
686 28
    public function getGroupingIdentifier()
687
    {
688 28
        return $this->groupingIdentifier;
689
    }
690
691
    /**
692
     * {@inheritdoc}
693
     */
694 1
    public function setLabelColor($labelColor)
695
    {
696 1
        $this->labelColor = $labelColor;
697
698 1
        return $this;
699
    }
700
701
    /**
702
     * {@inheritdoc}
703
     */
704 12
    public function getLabelColor()
705
    {
706 12
        return $this->labelColor;
707
    }
708
709
    /**
710
     * {@inheritdoc}
711
     */
712 2
    public function setStripColor($stripColor): self
713
    {
714 2
        $this->stripColor = $stripColor;
715
716 2
        return $this;
717
    }
718
719
    /**
720
     * {@inheritdoc}
721
     */
722 12
    public function getStripColor(): ?string
723
    {
724 12
        return $this->stripColor;
725
    }
726
727
    /**
728
     * {@inheritdoc}
729
     */
730 4
    public function setLogoText($logoText)
731
    {
732 4
        $this->logoText = $logoText;
733
734 4
        return $this;
735
    }
736
737
    /**
738
     * {@inheritdoc}
739
     */
740 12
    public function getLogoText()
741
    {
742 12
        return $this->logoText;
743
    }
744
745
    /**
746
     * {@inheritdoc}
747
     */
748 1
    public function setSuppressStripShine($suppressStripShine)
749
    {
750 1
        $this->suppressStripShine = $suppressStripShine;
751
752 1
        return $this;
753
    }
754
755
    /**
756
     * {@inheritdoc}
757
     */
758 12
    public function getSuppressStripShine()
759
    {
760 12
        return $this->suppressStripShine;
761
    }
762
763
    /**
764
     * {@inheritdoc}
765
     */
766 2
    public function setAuthenticationToken($authenticationToken)
767
    {
768 2
        $this->authenticationToken = $authenticationToken;
769
770 2
        return $this;
771
    }
772
773
    /**
774
     * {@inheritdoc}
775
     */
776 13
    public function getAuthenticationToken()
777
    {
778 13
        return (string) $this->authenticationToken;
779
    }
780
781
    /**
782
     * {@inheritdoc}
783
     */
784 2
    public function setWebServiceURL($webServiceURL)
785
    {
786 2
        $this->webServiceURL = $webServiceURL;
787
788 2
        return $this;
789
    }
790
791
    /**
792
     * {@inheritdoc}
793
     */
794 28
    public function getWebServiceURL()
795
    {
796 28
        return $this->webServiceURL;
797
    }
798
799
    /**
800
     * {@inheritdoc}
801
     */
802 5
    public function setPassTypeIdentifier($passTypeIdentifier)
803
    {
804 5
        $this->passTypeIdentifier = $passTypeIdentifier;
805
806 5
        return $this;
807
    }
808
809
    /**
810
     * {@inheritdoc}
811
     */
812 28
    public function getPassTypeIdentifier()
813
    {
814 28
        return $this->passTypeIdentifier;
815
    }
816
817
    /**
818
     * {@inheritdoc}
819
     */
820 5
    public function setTeamIdentifier($teamIdentifier)
821
    {
822 5
        $this->teamIdentifier = $teamIdentifier;
823
824 5
        return $this;
825
    }
826
827
    /**
828
     * {@inheritdoc}
829
     */
830 28
    public function getTeamIdentifier()
831
    {
832 28
        return $this->teamIdentifier;
833
    }
834
835
    /**
836
     * {@inheritdoc}
837
     */
838 5
    public function setOrganizationName($organizationName)
839
    {
840 5
        $this->organizationName = $organizationName;
841
842 5
        return $this;
843
    }
844
845
    /**
846
     * {@inheritdoc}
847
     */
848 28
    public function getOrganizationName()
849
    {
850 28
        return $this->organizationName;
851
    }
852
853
    /**
854
     * {@inheritdoc}
855
     */
856
    public function setExpirationDate(DateTime $expirationDate)
857
    {
858
        $this->expirationDate = $expirationDate;
859
860
        return $this;
861
    }
862
863
    /**
864
     * {@inheritdoc}
865
     */
866 12
    public function getExpirationDate()
867
    {
868 12
        return $this->expirationDate;
869
    }
870
871
    /**
872
     * {@inheritdoc}
873
     */
874
    public function setVoided($voided)
875
    {
876
        $this->voided = $voided;
877
878
        return $this;
879
    }
880
881
    /**
882
     * {@inheritdoc}
883
     */
884 12
    public function getVoided()
885
    {
886 12
        return $this->voided;
887
    }
888
889
    /**
890
     * {@inheritdoc}
891
     */
892 2
    public function setAppLaunchURL($appLaunchURL)
893
    {
894 2
        $this->appLaunchURL = $appLaunchURL;
895
896 2
        return $this;
897
    }
898
899
    /**
900
     * {@inheritdoc}
901
     */
902 28
    public function getAppLaunchURL()
903
    {
904 28
        return $this->appLaunchURL;
905
    }
906
907
    /**
908
     * {@inheritdoc}
909
     */
910
    public function setUserInfo($userInfo)
911
    {
912
        $this->userInfo = $userInfo;
913
914
        return $this;
915
    }
916
917
    /**
918
     * {@inheritdoc}
919
     */
920 12
    public function getUserInfo()
921
    {
922 12
        return $this->userInfo;
923
    }
924
925
    public function setSharingProhibited(bool $value): self
926
    {
927
        $this->sharingProhibited = $value;
928
929
        return $this;
930
    }
931
932 12
    public function getSharingProhibited(): bool
933
    {
934 12
        return $this->sharingProhibited;
935
    }
936
}
937