Pass::getSuppressStripShine()   A
last analyzed

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