Passed
Push — google-wallet-support ( 15e26d...cd8842 )
by Razvan
04:15
created

PassFields::addBackField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Apple;
13
14
use Passbook\ArrayableInterface;
15
16
/**
17
 * Pass Structure
18
 *
19
 * @author Eymen Gunay <[email protected]>
20
 * @see https://developer.apple.com/documentation/walletpasses/passfields
21
 */
22
class PassFields implements ArrayableInterface
23
{
24
    /**
25
     * Fields to be displayed in the header on the front of the pass.
26
     * @var FieldInterface[]
27
     */
28
    public array $headerFields = [];
29
30
    /**
31
     * Fields to be displayed prominently on the front of the pass.
32
     * @var FieldInterface[]
33
     */
34
    public array $primaryFields = [];
35
36
    /**
37
     * Fields to be displayed on the front of the pass.
38
     * @var FieldInterface[]
39
     */
40
    public array $secondaryFields = [];
41
42
    /**
43
     * Additional fields to be displayed on the front of the pass.
44
     * @var FieldInterface[]
45
     */
46
    public array $auxiliaryFields = [];
47
48
    /**
49
     * Fields to be on the back of the pass.
50
     * @var FieldInterface[]
51
     */
52
    public array $backFields = [];
53
54 6
    public function toArray()
55
    {
56 6
        $array = [];
57
58 6
        foreach ($this->getHeaderFields() as $headerField) {
59 2
            $array['headerFields'][] = $headerField->toArray();
60
        }
61
62 6
        foreach ($this->getPrimaryFields() as $primaryField) {
63 4
            $array['primaryFields'][] = $primaryField->toArray();
64
        }
65
66 6
        foreach ($this->getSecondaryFields() as $secondaryField) {
67 4
            $array['secondaryFields'][] = $secondaryField->toArray();
68
        }
69
70 6
        foreach ($this->getAuxiliaryFields() as $auxiliaryField) {
71 4
            $array['auxiliaryFields'][] = $auxiliaryField->toArray();
72
        }
73
74 6
        foreach ($this->getBackFields() as $backField) {
75 2
            $array['backFields'][] = $backField->toArray();
76
        }
77
78 6
        return empty($array) ? (object)null : $array;
0 ignored issues
show
Bug Best Practice introduced by
The expression return empty($array) ? (object)null : $array also could return the type object which is incompatible with the return type mandated by Passbook\ArrayableInterface::toArray() of array.
Loading history...
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 2
    public function addHeaderField(FieldInterface $headerField)
85
    {
86 2
        $this->headerFields[] = $headerField;
87
88 2
        return $this;
89
    }
90
91
    /**
92
     * @return FieldInterface[]
93
     */
94 6
    public function getHeaderFields(): array
95
    {
96 6
        return $this->headerFields;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 4
    public function addPrimaryField(FieldInterface $primaryField)
103
    {
104 4
        $this->primaryFields[] = $primaryField;
105
106 4
        return $this;
107
    }
108
109
    /**
110
     * @return FieldInterface[]
111
     */
112 6
    public function getPrimaryFields(): array
113
    {
114 6
        return $this->primaryFields;
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120 4
    public function addSecondaryField(FieldInterface $secondaryField)
121
    {
122 4
        $this->secondaryFields[] = $secondaryField;
123
124 4
        return $this;
125
    }
126
127
    /**
128
     * @return FieldInterface[]
129
     */
130 6
    public function getSecondaryFields(): array
131
    {
132 6
        return $this->secondaryFields;
133
    }
134
135
    /**
136
     * {@inheritdoc}
137
     */
138 4
    public function addAuxiliaryField(FieldInterface $auxiliaryField)
139
    {
140 4
        $this->auxiliaryFields[] = $auxiliaryField;
141
142 4
        return $this;
143
    }
144
145
    /**
146
     * @return FieldInterface[]
147
     */
148 6
    public function getAuxiliaryFields(): array
149
    {
150 6
        return $this->auxiliaryFields;
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156 2
    public function addBackField(FieldInterface $backField)
157
    {
158 2
        $this->backFields[] = $backField;
159
160 2
        return $this;
161
    }
162
163
    /**
164
     * @return FieldInterface[]
165
     */
166 6
    public function getBackFields(): array
167
    {
168 6
        return $this->backFields;
169
    }
170
}
171