Passed
Push — master ( a94b97...2fde7e )
by Razvan
03:25
created

Pass::setExpirationDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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