Passed
Pull Request — master (#105)
by
unknown
02:51
created

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