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

PassFieldContent::getLabel()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
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
/**
15
 * Field
16
 * @author Eymen Gunay <[email protected]>
17
 * @see https://developer.apple.com/documentation/walletpasses/passfieldcontent
18
 */
19
abstract class PassFieldContent implements FieldInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    public const ALIGN_LEFT = 'PKTextAlignmentLeft';
25
26
    /**
27
     * @var string
28
     */
29
    public const ALIGN_CENTER = 'PKTextAlignmentCenter';
30
31
    /**
32
     * @var string
33
     */
34
    public const ALIGN_RIGHT = 'PKTextAlignmentRight';
35
36
    /**
37
     * @var string
38
     */
39
    public const ALIGN_NATURAL = 'PKTextAlignmentNatural';
40
41
    /**
42
     * @var string
43
     */
44
    public const DATA_DETECTOR_TYPE_PHONE_NUMBER = 'PKDataDetectorTypePhoneNumber';
45
46
    /**
47
     * @var string
48
     */
49
    public const DATA_DETECTOR_TYPE_LINK = 'PKDataDetectorTypeLink';
50
51
    /**
52
     * @var string
53
     */
54
    public const DATA_DETECTOR_TYPE_ADDRESS = 'PKDataDetectorTypeAddress';
55
56
    /**
57
     * @var string
58
     */
59
    public const DATA_DETECTOR_TYPE_CALENDAR_EVENT = 'PKDataDetectorTypeCalendarEvent';
60
61
    /**
62
     * Format string for the alert text that is displayed when the pass is updated.
63
     * The format string may contain the escape %@, which is replaced with the
64
     * field’s new value. For example, “Gate changed to %@.”
65
     * @var string
66
     */
67
    protected $changeMessage;
68
69
    /**
70
     * The key must be unique within the scope of the entire pass.
71
     * For example, “departure-gate”.
72
     * @var string
73
     */
74
    protected $key;
75
76
    /**
77
     * Label text for the field.
78
     * @var string
79
     */
80
    protected $label;
81
82
    /**
83
     * Alignment for the field’s contents. Must be one of the following values:
84
     * PKTextAlignmentLeft, PKTextAlignmentCenter, PKTextAlignmentRight, PKTextAlignmentNatural
85
     * The default value is natural alignment,
86
     * which aligns the text appropriately based on its script direction.
87
     * This key is not allowed for primary fields.
88
     * @var string
89
     */
90
    protected $textAlignment;
91
92
    /**
93
     * Value of the field. For example, 42.
94
     * @var mixed ISO 8601 date as a string, or number
95
     */
96
    protected $value;
97
98
    /**
99
     * Array of strings
100
     * The default value is all data detectors. Provide an empty array to use no data detectors.
101
     * Data detectors are applied only to back fields.
102
     * @link https://developer.apple.com/library/ios/documentation/userexperience/Reference/PassKit_Bundle/Chapters/FieldDictionary.html#//apple_ref/doc/uid/TP40012026-CH4-SW1
103
     * @var array
104
     */
105
    protected $dataDetectorTypes;
106
107
    /**
108
     * Localizable string, ISO 8601 date as a string, or number
109
     * @var string
110
     */
111
    protected $attributedValue;
112
113 9
    public function __construct($key, $value)
114
    {
115
        // Required
116 9
        $this->setKey($key);
117 9
        $this->setValue($value);
118
    }
119
120 8
    public function toArray()
121
    {
122 8
        $array = [
123 8
            'key' => $this->getKey(),
124 8
            'value' => $this->getValue()
125 8
        ];
126
127 8
        if ($this->getChangeMessage()) {
128 1
            $array['changeMessage'] = $this->getChangeMessage();
129
        }
130
131 8
        if ($this->getLabel()) {
132 4
            $array['label'] = $this->getLabel();
133
        }
134
135 8
        if ($this->getTextAlignment()) {
136 1
            $array['textAlignment'] = $this->getTextAlignment();
137
        }
138
139 8
        if ($this->getDataDetectorTypes()) {
140
            $array['dataDetectorTypes'] = $this->getDataDetectorTypes();
141
        }
142
143 8
        if ($this->getAttributedValue()) {
144
            $array['attributedValue'] = $this->getAttributedValue();
145
        }
146
147 8
        return $array;
148
    }
149
150
    /**
151
     * {@inheritdoc}
152
     */
153 1
    public function setChangeMessage($changeMessage)
154
    {
155 1
        $this->changeMessage = $changeMessage;
156
157 1
        return $this;
158
    }
159
160
    /**
161
     * {@inheritdoc}
162
     */
163 8
    public function getChangeMessage()
164
    {
165 8
        return $this->changeMessage;
166
    }
167
168
    /**
169
     * {@inheritdoc}
170
     */
171 9
    public function setKey($key)
172
    {
173 9
        $this->key = $key;
174
175 9
        return $this;
176
    }
177
178
    /**
179
     * {@inheritdoc}
180
     */
181 8
    public function getKey()
182
    {
183 8
        return $this->key;
184
    }
185
186
    /**
187
     * {@inheritdoc}
188
     */
189 4
    public function setLabel($label)
190
    {
191 4
        $this->label = $label;
192
193 4
        return $this;
194
    }
195
196
    /**
197
     * {@inheritdoc}
198
     */
199 8
    public function getLabel()
200
    {
201 8
        return $this->label;
202
    }
203
204
    /**
205
     * {@inheritdoc}
206
     */
207 1
    public function setTextAlignment($textAlignment)
208
    {
209 1
        $this->textAlignment = $textAlignment;
210
211 1
        return $this;
212
    }
213
214
    /**
215
     * {@inheritdoc}
216
     */
217 8
    public function getTextAlignment()
218
    {
219 8
        return $this->textAlignment;
220
    }
221
222
    /**
223
     * {@inheritdoc}
224
     */
225 9
    public function setValue($value)
226
    {
227 9
        $this->value = $value;
228
229 9
        return $this;
230
    }
231
232
    /**
233
     * {@inheritdoc}
234
     */
235 9
    public function getValue()
236
    {
237 9
        return $this->value;
238
    }
239
240
    /**
241
     * {@inheritdoc}
242
     */
243
    public function setAttributedValue($attributedValue)
244
    {
245
        $this->attributedValue = $attributedValue;
246
        return $this;
247
    }
248
249
    /**
250
     * {@inheritdoc}
251
     */
252 8
    public function getAttributedValue()
253
    {
254 8
        return $this->attributedValue;
255
    }
256
257
    /**
258
     * {@inheritdoc}
259
     */
260
    public function setDataDetectorTypes(array $dataDetectorTypes)
261
    {
262
        $this->dataDetectorTypes = $dataDetectorTypes;
263
        return $this;
264
    }
265
266
    /**
267
     * {@inheritdoc}
268
     */
269 8
    public function getDataDetectorTypes()
270
    {
271 8
        return $this->dataDetectorTypes;
272
    }
273
}
274