Completed
Push — master ( a5b05f...ea8859 )
by Eymen
18s queued 12s
created

Pass::addImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 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\ImageInterface;
18
use Passbook\Pass\LocalizationInterface;
19
use Passbook\Pass\LocationInterface;
20
use Passbook\Pass\Structure;
21
use Passbook\Pass\StructureInterface;
22
23
/**
24
 * Pass
25
 *
26
 * @author Eymen Gunay <[email protected]>
27
 * @author Sotaro Omura <http://omoon.org>
28
 * @author Dzamir <https://github.com/Dzamir>
29
 */
30
class Pass implements PassInterface
31
{
32
    /**
33
     * Serial number that uniquely identifies the pass.
34
     * No two passes with the same pass type identifier
35
     * may have the same serial number.
36
     *
37
     * @var string
38
     */
39
    protected $serialNumber;
40
41
    /**
42
     * Brief description of the pass,
43
     * used by the iOS accessibility technologies.
44
     *
45
     * @var string
46
     */
47
    protected $description;
48
49
    /**
50
     * Version of the file format.
51
     * The value must be 1.
52
     *
53
     * @var int
54
     */
55
    protected $formatVersion = 1;
56
57
    /**
58
     * Pass type
59
     *
60
     * @var string
61
     */
62
    protected $type;
63
64
    /**
65
     * Pass structure
66
     *
67
     * @var Structure
68
     */
69
    protected $structure;
70
71
    /**
72
     * Pass images
73
     *
74
     * @var ImageInterface[]
75
     */
76
    protected $images = [];
77
78
    /**
79
     * Beacons where the pass is relevant.
80
     *
81
     * @var array
82
     */
83
    protected $beacons = [];
84
85
    /**
86
     * A list of iTunes Store item identifiers (also known as Adam IDs) for the
87
     * associated apps.
88
     *
89
     * Only one item in the list is used—the first item identifier for an app
90
     * compatible with the current device. If the app is not installed, the
91
     * link opens the App Store and shows the app. If the app is already
92
     * installed, the link launches the app.
93
     *
94
     * @var int[]
95
     */
96
    protected $associatedStoreIdentifiers = [];
97
98
    /**
99
     * Locations where the pass is relevant.
100
     * For example, the location of your store.
101
     *
102
     * @var array
103
     */
104
    protected $locations = [];
105
106
    /**
107
     * List of localizations
108
     *
109
     * @var LocalizationInterface[]
110
     */
111
    protected $localizations = [];
112
113
    /**
114
     * Date and time when the pass becomes relevant.
115
     * For example, the start time of a movie.
116
     *
117
     * @var DateTime
118
     */
119
    protected $relevantDate;
120
121
    /**
122
     * Maximum distance in meters from a relevant latitude and longitude that
123
     * the pass is relevant. This number is compared to the pass’s default
124
     * distance and the smaller value is used.
125
     * Available in iOS 7.0.
126
     * @var int
127
     */
128
    protected $maxDistance;
129
130
    /**
131
     * Barcodes available to be displayed of iOS 9 and later. The system uses
132
     * the first valid barcode in the array.
133
     * @var BarcodeInterface[]
134
     */
135
    protected $barcodes = [];
136
137
    /**
138
     * Barcode to be displayed for iOS 8 and earlier.
139
     * @var BarcodeInterface
140
     */
141
    protected $barcode;
142
143
    /**
144
     * Background color of the pass, specified as an CSS-style RGB triple.
145
     *
146
     * @var string rgb(23, 187, 82)
147
     */
148
    protected $backgroundColor;
149
150
    /**
151
     * Foreground color of the pass, specified as a CSS-style RGB triple.
152
     *
153
     * @var string rgb(100, 10, 110)
154
     */
155
    protected $foregroundColor;
156
157
    /**
158
     * Identifier used to group related passes.
159
     * If a grouping identifier is specified, passes with the same style, pass type identifier,
160
     * and grouping identifier are displayed as a group. Otherwise, passes are grouped automatically.
161
     *
162
     * @var string
163
     */
164
    protected $groupingIdentifier;
165
166
    /**
167
     * Color of the label text, specified as a CSS-style RGB triple.
168
     *
169
     * @var string rgb(255, 255, 255)
170
     */
171
    protected $labelColor;
172
173
    /**
174
     * Text displayed next to the logo on the pass.
175
     *
176
     * @var string
177
     */
178
    protected $logoText;
179
180
    /**
181
     * If true, the strip image is displayed without a shine effect.
182
     *
183
     * @var string The default value is false
184
     */
185
    protected $suppressStripShine;
186
187
    /**
188
     * The authentication token to use with the web service.
189
     * The token must be 16 characters or longer.
190
     *
191
     * @var string
192
     */
193
    protected $authenticationToken;
194
195
    /**
196
     * The URL of a web service that conforms to the API described in Passbook Web Service Reference.
197
     * http://developer.apple.com/library/ios/documentation/PassKit/Reference/PassKit_WebService/WebService.html#//apple_ref/doc/uid/TP40011988
198
     *
199
     * @var string
200
     */
201
    protected $webServiceURL;
202
203
    /**
204
     * Pass type identifier
205
     *
206
     * @var string
207
     */
208
    protected $passTypeIdentifier;
209
210
    /**
211
     * Team identifier
212
     *
213
     * @var string
214
     */
215
    protected $teamIdentifier;
216
217
    /**
218
     * Organization name
219
     *
220
     * @var string
221
     */
222
    protected $organizationName;
223
224
    /**
225
     * Date and time when the pass expires.
226
     *
227
     * @var DateTime
228
     */
229
    protected $expirationDate;
230
231
    /**
232
     * Indicates that the pass is void—for example, a one time use coupon that has been redeemed. The default value is
233
     * false.
234
     *
235
     * @var boolean
236
     */
237
    protected $voided;
238
239
    /**
240
     *
241
     * A URL to be passed to the associated app when launching it.
242
     * The app receives this URL in the application:didFinishLaunchingWithOptions: and application:handleOpenURL:
243
     * methods of its app delegate. If this key is present, the associatedStoreIdentifiers key must also be present.
244
     *
245
     * @var string
246
     */
247
    protected $appLaunchURL;
248
249
	/**
250
	 * Pass userInfo
251
	 *
252
	 * @var mixed
253
	 */
254
	protected $userInfo;
255
256
    /**
257
     *
258
     * Flag to decide if the pass can be shared or not.
259
     *
260
     * @var bool
261
     *
262
     */
263
	protected bool $sharingProhibited = false;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
264
265
    public function __construct($serialNumber, $description)
266
    {
267
        // Required
268
        $this->setSerialNumber($serialNumber);
269
        $this->setDescription($description);
270
    }
271
272
    public function toArray()
273
    {
274
        $array = [];
275
276
        // Structure
277
        if ($this->getStructure()) {
278
            $array[$this->getType()] = $this->getStructure()->toArray();
279
        }
280
281
        $properties = array(
282
            'serialNumber',
283
            'description',
284
            'formatVersion',
285
            'beacons',
286
            'locations',
287
            'maxDistance',
288
            'relevantDate',
289
            'barcode',
290
            'barcodes',
291
            'backgroundColor',
292
            'foregroundColor',
293
            'groupingIdentifier',
294
            'labelColor',
295
            'logoText',
296
            'suppressStripShine',
297
            'authenticationToken',
298
            'webServiceURL',
299
            'passTypeIdentifier',
300
            'teamIdentifier',
301
            'organizationName',
302
            'expirationDate',
303
            'voided',
304
            'appLaunchURL',
305
            'associatedStoreIdentifiers',
306
	        'userInfo',
307
            'sharingProhibited'
308
        );
309
        foreach ($properties as $property) {
310
            $method = 'is' . ucfirst($property);
311
            if (!method_exists($this, $method)) {
312
                $method = 'get' . ucfirst($property);
313
            }
314
            $val = $this->$method();
315
            if ($val instanceof DateTime) {
316
                // Date
317
                $array[$property] = $val->format('c');
318
            } elseif (is_object($val)) {
319
                // Object
320
                /* @var ArrayableInterface $val */
321
                $array[$property] = $val->toArray();
322
            } elseif (is_scalar($val)) {
323
                // Scalar
324
                $array[$property] = $val;
325
            } elseif (is_array($val)) {
326
                // Array
327
                foreach ($val as $k => $v) {
328
                    if (is_object($v)) {
329
                        /* @var ArrayableInterface $v */
330
                        $array[$property][$k] = $v->toArray();
331
                    } else {
332
                        $array[$property][$k] = $v;
333
                    }
334
                }
335
            }
336
        }
337
        if ($this->getAssociatedStoreIdentifiers()) {
338
            $array['associatedStoreIdentifiers'] = $this->getAssociatedStoreIdentifiers();
339
        }
340
341
        return $array;
342
    }
343
344
    /**
345
     * {@inheritdoc}
346
     */
347
    public function setSerialNumber($serialNumber)
348
    {
349
        $this->serialNumber = strval($serialNumber);
350
351
        return $this;
352
    }
353
354
    /**
355
     * {@inheritdoc}
356
     */
357
    public function getSerialNumber()
358
    {
359
        return $this->serialNumber;
360
    }
361
362
    /**
363
     * {@inheritdoc}
364
     */
365
    public function setDescription($description)
366
    {
367
        $this->description = $description;
368
369
        return $this;
370
    }
371
372
    /**
373
     * {@inheritdoc}
374
     */
375
    public function getDescription()
376
    {
377
        return $this->description;
378
    }
379
380
    /**
381
     * {@inheritdoc}
382
     */
383
    public function getFormatVersion()
384
    {
385
        return $this->formatVersion;
386
    }
387
388
    /**
389
     * {@inheritdoc}
390
     */
391
    public function setFormatVersion($formatVersion)
392
    {
393
        $this->formatVersion = $formatVersion;
394
395
        return $this;
396
    }
397
398
    /**
399
     * {@inheritdoc}
400
     */
401
    public function getType()
402
    {
403
        return $this->type;
404
    }
405
406
    /**
407
     * {@inheritdoc}
408
     */
409
    public function setType($type)
410
    {
411
        $this->type = $type;
412
413
        return $this;
414
    }
415
416
    /**
417
     * {@inheritdoc}
418
     */
419
    public function setStructure(StructureInterface $structure)
420
    {
421
        $this->structure = $structure;
422
423
        return $this;
424
    }
425
426
    /**
427
     * {@inheritdoc}
428
     */
429
    public function getStructure()
430
    {
431
        return $this->structure;
432
    }
433
434
    /**
435
     * {@inheritdoc}
436
     */
437
    public function addImage(ImageInterface $image)
438
    {
439
        $this->images[] = $image;
440
441
        return $this;
442
    }
443
444
    /**
445
     * {@inheritdoc}
446
     */
447
    public function getImages()
448
    {
449
        return $this->images;
450
    }
451
452
    /**
453
     * {@inheritdoc}
454
     */
455
    public function addLocalization(LocalizationInterface $localization)
456
    {
457
        $this->localizations[] = $localization;
458
459
        return $this;
460
    }
461
462
    /**
463
     * {@inheritdoc}
464
     */
465
    public function getLocalizations()
466
    {
467
        return $this->localizations;
468
    }
469
470
    /**
471
     * {@inheritdoc}
472
     */
473
    public function addAssociatedStoreIdentifier($associatedStoreIdentifier)
474
    {
475
        $this->associatedStoreIdentifiers[] = $associatedStoreIdentifier;
476
477
        return $this;
478
    }
479
480
    /**
481
     * {@inheritdoc}
482
     */
483
    public function getAssociatedStoreIdentifiers()
484
    {
485
        return $this->associatedStoreIdentifiers;
486
    }
487
488
    /**
489
     * {@inheritdoc}
490
     */
491
    public function addLocation(LocationInterface $location)
492
    {
493
        $this->locations[] = $location;
494
495
        return $this;
496
    }
497
498
    /**
499
     * {@inheritdoc}
500
     */
501
    public function getLocations()
502
    {
503
        return $this->locations;
504
    }
505
506
    /**
507
     * {@inheritdoc}
508
     */
509
    public function addBeacon(BeaconInterface $beacon)
510
    {
511
        $this->beacons[] = $beacon;
512
513
        return $this;
514
    }
515
516
    /**
517
     * {@inheritdoc}
518
     */
519
    public function getBeacons()
520
    {
521
        return $this->beacons;
522
    }
523
524
    /**
525
     * {@inheritdoc}
526
     */
527
    public function setRelevantDate(DateTime $relevantDate)
528
    {
529
        $this->relevantDate = $relevantDate;
530
531
        return $this;
532
    }
533
534
    /**
535
     * {@inheritdoc}
536
     */
537
    public function getRelevantDate()
538
    {
539
        return $this->relevantDate;
540
    }
541
542
    /**
543
     * {@inheritdoc}
544
     */
545
    public function setMaxDistance($maxDistance)
546
    {
547
        $this->maxDistance = $maxDistance;
548
549
        return $this;
550
    }
551
552
    /**
553
     * {@inheritdoc}
554
     */
555
    public function getMaxDistance()
556
    {
557
        return $this->maxDistance;
558
    }
559
560
    /**
561
     * {@inheritdoc}
562
     */
563
    public function setBarcode(BarcodeInterface $barcode)
564
    {
565
        $this->barcode = $barcode;
566
        array_unshift($this->barcodes, $barcode);
567
568
        return $this;
569
    }
570
571
    /**
572
     * {@inheritdoc}
573
     */
574
    public function getBarcode()
575
    {
576
        return $this->barcode;
577
    }
578
579
    /**
580
     * {@inheritdoc}
581
     */
582
    public function addBarcode(BarcodeInterface $barcode)
583
    {
584
        $this->barcodes[] = $barcode;
585
586
        if (empty($this->barcode)) {
587
            $this->barcode = $barcode;
588
        }
589
590
        return $this;
591
    }
592
593
    /**
594
     * {@inheritdoc}
595
     */
596
    public function getBarcodes()
597
    {
598
        return $this->barcodes;
599
    }
600
601
    /**
602
     * {@inheritdoc}
603
     */
604
    public function setBackgroundColor($backgroundColor)
605
    {
606
        $this->backgroundColor = $backgroundColor;
607
608
        return $this;
609
    }
610
611
    /**
612
     * {@inheritdoc}
613
     */
614
    public function getBackgroundColor()
615
    {
616
        return $this->backgroundColor;
617
    }
618
619
    /**
620
     * {@inheritdoc}
621
     */
622
    public function setForegroundColor($foregroundColor)
623
    {
624
        $this->foregroundColor = $foregroundColor;
625
626
        return $this;
627
    }
628
629
    /**
630
     * {@inheritdoc}
631
     */
632
    public function getForegroundColor()
633
    {
634
        return $this->foregroundColor;
635
    }
636
637
    /**
638
     * {@inheritdoc}
639
     */
640
    public function setGroupingIdentifier($groupingIdentifier)
641
    {
642
        $this->groupingIdentifier = $groupingIdentifier;
643
644
        return $this;
645
    }
646
647
    /**
648
     * {@inheritdoc}
649
     */
650
    public function getGroupingIdentifier()
651
    {
652
        return $this->groupingIdentifier;
653
    }
654
655
    /**
656
     * {@inheritdoc}
657
     */
658
    public function setLabelColor($labelColor)
659
    {
660
        $this->labelColor = $labelColor;
661
662
        return $this;
663
    }
664
665
    /**
666
     * {@inheritdoc}
667
     */
668
    public function getLabelColor()
669
    {
670
        return $this->labelColor;
671
    }
672
673
    /**
674
     * {@inheritdoc}
675
     */
676
    public function setLogoText($logoText)
677
    {
678
        $this->logoText = $logoText;
679
680
        return $this;
681
    }
682
683
    /**
684
     * {@inheritdoc}
685
     */
686
    public function getLogoText()
687
    {
688
        return $this->logoText;
689
    }
690
691
    /**
692
     * {@inheritdoc}
693
     */
694
    public function setSuppressStripShine($suppressStripShine)
695
    {
696
        $this->suppressStripShine = $suppressStripShine;
697
698
        return $this;
699
    }
700
701
    /**
702
     * {@inheritdoc}
703
     */
704
    public function getSuppressStripShine()
705
    {
706
        return $this->suppressStripShine;
707
    }
708
709
    /**
710
     * {@inheritdoc}
711
     */
712
    public function setAuthenticationToken($authenticationToken)
713
    {
714
        $this->authenticationToken = $authenticationToken;
715
716
        return $this;
717
    }
718
719
    /**
720
     * {@inheritdoc}
721
     */
722
    public function getAuthenticationToken()
723
    {
724
        return $this->authenticationToken;
725
    }
726
727
    /**
728
     * {@inheritdoc}
729
     */
730
    public function setWebServiceURL($webServiceURL)
731
    {
732
        $this->webServiceURL = $webServiceURL;
733
734
        return $this;
735
    }
736
737
    /**
738
     * {@inheritdoc}
739
     */
740
    public function getWebServiceURL()
741
    {
742
        return $this->webServiceURL;
743
    }
744
745
    /**
746
     * {@inheritdoc}
747
     */
748
    public function setPassTypeIdentifier($passTypeIdentifier)
749
    {
750
        $this->passTypeIdentifier = $passTypeIdentifier;
751
752
        return $this;
753
    }
754
755
    /**
756
     * {@inheritdoc}
757
     */
758
    public function getPassTypeIdentifier()
759
    {
760
        return $this->passTypeIdentifier;
761
    }
762
763
    /**
764
     * {@inheritdoc}
765
     */
766
    public function setTeamIdentifier($teamIdentifier)
767
    {
768
        $this->teamIdentifier = $teamIdentifier;
769
770
        return $this;
771
    }
772
773
    /**
774
     * {@inheritdoc}
775
     */
776
    public function getTeamIdentifier()
777
    {
778
        return $this->teamIdentifier;
779
    }
780
781
    /**
782
     * {@inheritdoc}
783
     */
784
    public function setOrganizationName($organizationName)
785
    {
786
        $this->organizationName = $organizationName;
787
788
        return $this;
789
    }
790
791
    /**
792
     * {@inheritdoc}
793
     */
794
    public function getOrganizationName()
795
    {
796
        return $this->organizationName;
797
    }
798
799
    /**
800
     * {@inheritdoc}
801
     */
802
    public function setExpirationDate(DateTime $expirationDate)
803
    {
804
        $this->expirationDate = $expirationDate;
805
806
        return $this;
807
    }
808
809
    /**
810
     * {@inheritdoc}
811
     */
812
    public function getExpirationDate()
813
    {
814
        return $this->expirationDate;
815
    }
816
817
    /**
818
     * {@inheritdoc}
819
     */
820
    public function setVoided($voided)
821
    {
822
        $this->voided = $voided;
823
824
        return $this;
825
    }
826
827
    /**
828
     * {@inheritdoc}
829
     */
830
    public function getVoided()
831
    {
832
        return $this->voided;
833
    }
834
835
    /**
836
     * {@inheritdoc}
837
     */
838
    public function setAppLaunchURL($appLaunchURL)
839
    {
840
        $this->appLaunchURL = $appLaunchURL;
841
842
        return $this;
843
    }
844
845
    /**
846
     * {@inheritdoc}
847
     */
848
    public function getAppLaunchURL()
849
    {
850
        return $this->appLaunchURL;
851
    }
852
853
	/**
854
	 * {@inheritdoc}
855
	 */
856
	public function setUserInfo($userInfo) {
857
		$this->userInfo = $userInfo;
858
859
		return $this;
860
	}
861
862
	/**
863
	 * {@inheritdoc}
864
	 */
865
	public function getUserInfo() {
866
		return $this->userInfo;
867
	}
868
869
	public function setSharingProhibited(bool $value): self
870
    {
871
	    $this->sharingProhibited = $value;
872
873
	    return $this;
874
    }
875
876
    public function getSharingProhibited(): bool {
877
	    return $this->sharingProhibited;
878
    }
879
880
}
881