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

DateField::toArray()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6.2017

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 16
nop 0
dl 0
loc 18
ccs 7
cts 11
cp 0.6364
crap 6.2017
rs 9.6111
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
 * Class DateField
16
 * @package Passbook\Pass
17
 * @link https://developer.apple.com/library/ios/documentation/userexperience/Reference/PassKit_Bundle/Chapters/FieldDictionary.html#//apple_ref/doc/uid/TP40012026-CH4-SW1
18
 * @author Florian Morello <[email protected]>
19
 */
20
class DateField extends Field
21
{
22
    /**
23
     * @var string
24
     */
25
    public const DATE_STYLE_NONE = 'PKDateStyleNone';
26
27
    /**
28
     * @var string
29
     */
30
    public const DATE_STYLE_SHORT = 'PKDateStyleShort';
31
32
    /**
33
     * @var string
34
     */
35
    public const DATE_STYLE_MEDIUM = 'PKDateStyleMedium';
36
37
    /**
38
     * @var string
39
     */
40
    public const DATE_STYLE_LONG = 'PKDateStyleLong';
41
42
    /**
43
     * @var string
44
     */
45
    public const DATE_STYLE_FULL = 'PKDateStyleFull';
46
47
    /**
48
     * @var string
49
     */
50
    protected $dateStyle;
51
52
    /**
53
     * @var bool
54
     */
55
    protected $ignoresTimeZone;
56
57
    /**
58
     * @var bool
59
     */
60
    protected $isRelative;
61
62
    /**
63
     * @var string
64
     */
65
    protected $timeStyle;
66
67
    /**
68
     * @return array
69
     */
70 1
    public function toArray()
71
    {
72 1
        $array = parent::toArray();
73
74 1
        if (strlen($this->getDateStyle())) {
75
            $array['dateStyle'] = $this->getDateStyle();
76
        }
77 1
        if (is_bool($this->getIgnoresTimeZone())) {
0 ignored issues
show
introduced by
The condition is_bool($this->getIgnoresTimeZone()) is always true.
Loading history...
78
            $array['ignoresTimeZone'] = $this->getIgnoresTimeZone();
79
        }
80 1
        if (is_bool($this->getIsRelative())) {
0 ignored issues
show
introduced by
The condition is_bool($this->getIsRelative()) is always true.
Loading history...
81
            $array['isRelative'] = $this->getIsRelative();
82
        }
83 1
        if (strlen($this->getTimeStyle())) {
84
            $array['timeStyle'] = $this->getTimeStyle();
85
        }
86
87 1
        return $array;
88
    }
89
90
    /**
91
     * Must be one of PKDateStyle const
92
     * @param string $dateStyle
93
     */
94
    public function setDateStyle($dateStyle)
95
    {
96
        $this->dateStyle = $dateStyle;
97
98
        return $this;
99
    }
100
101
    /**
102
     * @return string
103
     */
104 1
    public function getDateStyle()
105
    {
106 1
        return (string) $this->dateStyle;
107
    }
108
109
    /**
110
     * @param boolean $ignoresTimeZone
111
     */
112
    public function setIgnoresTimeZone($ignoresTimeZone)
113
    {
114
        $this->ignoresTimeZone = $ignoresTimeZone;
115
116
        return $this;
117
    }
118
119
    /**
120
     * @return boolean
121
     */
122 1
    public function getIgnoresTimeZone()
123
    {
124 1
        return $this->ignoresTimeZone;
125
    }
126
127
    /**
128
     * @param boolean $isRelative
129
     */
130
    public function setIsRelative($isRelative)
131
    {
132
        $this->isRelative = $isRelative;
133
134
        return $this;
135
    }
136
137
    /**
138
     * @return boolean
139
     */
140 1
    public function getIsRelative()
141
    {
142 1
        return $this->isRelative;
143
    }
144
145
    /**
146
     * Must be one of PKDateStyle const
147
     * @param string $timeStyle
148
     */
149
    public function setTimeStyle($timeStyle)
150
    {
151
        $this->timeStyle = $timeStyle;
152
153
        return $this;
154
    }
155
156
    /**
157
     * @return string
158
     */
159 1
    public function getTimeStyle()
160
    {
161 1
        return (string) $this->timeStyle;
162
    }
163
164
    /**
165
     * Must be a ISO 8601 date string or a \DateTime object
166
     * @param string|\DateTime $value
167
     * @return $this
168
     */
169 1
    public function setValue($value)
170
    {
171 1
        if ($value instanceof \DateTime) {
172 1
            $value = $value->format('c');
173
        }
174
175 1
        return parent::setValue($value);
176
    }
177
}
178