DateField::getIsRelative()   A
last analyzed

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 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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\Pass;
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
 * @phpcs:disable Generic.NamingConventions.UpperCaseConstantName
20
 */
21
class DateField extends Field
22
{
23
    /**
24
     * @deprecated please use ::DATE_STYLE_NONE instead.
25
     */
26
    public const PKDateStyleNone = 'PKDateStyleNone';
27
28
    /**
29
     * @deprecated please use ::DATE_STYLE_SHORT instead.
30
     */
31
    public const PKDateStyleShort = 'PKDateStyleShort';
32
33
    /**
34
     * @deprecated please use ::DATE_STYLE_MEDIUM instead.
35
     */
36
    public const PKDateStyleMedium = 'PKDateStyleMedium';
37
38
    /**
39
     * @deprecated please use ::DATE_STYLE_LONG instead.
40
     */
41
    public const PKDateStyleLong = 'PKDateStyleLong';
42
43
    /**
44
     * @deprecated please use ::DATE_STYLE_FULL instead.
45
     */
46
    public const PKDateStyleFull = 'PKDateStyleFull';
47
48
    /**
49
     * @var string
50
     */
51
    public const DATE_STYLE_NONE = 'PKDateStyleNone';
52
53
    /**
54
     * @var string
55
     */
56
    public const DATE_STYLE_SHORT = 'PKDateStyleShort';
57
    /**
58
     * @var string
59
     */
60
    public const DATE_STYLE_MEDIUM = 'PKDateStyleMedium';
61
62
    /**
63
     * @var string
64
     */
65
    public const DATE_STYLE_LONG = 'PKDateStyleLong';
66
67
    /**
68
     * @var string
69
     */
70
    public const DATE_STYLE_FULL = 'PKDateStyleFull';
71
72
    /**
73
     * @var string
74
     */
75
    protected $dateStyle;
76
77
    /**
78
     * @var bool
79
     */
80
    protected $ignoresTimeZone;
81
82
    /**
83
     * @var bool
84
     */
85
    protected $isRelative;
86
87
    /**
88
     * @var string
89
     */
90
    protected $timeStyle;
91
92
    /**
93
     * @return array
94
     */
95 1
    public function toArray()
96
    {
97 1
        $array = parent::toArray();
98
99 1
        if (strlen($this->getDateStyle())) {
100
            $array['dateStyle'] = $this->getDateStyle();
101
        }
102 1
        if (is_bool($this->getIgnoresTimeZone())) {
0 ignored issues
show
introduced by
The condition is_bool($this->getIgnoresTimeZone()) is always true.
Loading history...
103
            $array['ignoresTimeZone'] = $this->getIgnoresTimeZone();
104
        }
105 1
        if (is_bool($this->getIsRelative())) {
0 ignored issues
show
introduced by
The condition is_bool($this->getIsRelative()) is always true.
Loading history...
106
            $array['isRelative'] = $this->getIsRelative();
107
        }
108 1
        if (strlen($this->getTimeStyle())) {
109
            $array['timeStyle'] = $this->getTimeStyle();
110
        }
111
112 1
        return $array;
113
    }
114
115
    /**
116
     * Must be one of PKDateStyle const
117
     * @param string $dateStyle
118
     */
119
    public function setDateStyle($dateStyle)
120
    {
121
        $this->dateStyle = $dateStyle;
122
123
        return $this;
124
    }
125
126
    /**
127
     * @return string
128
     */
129 1
    public function getDateStyle()
130
    {
131 1
        return (string) $this->dateStyle;
132
    }
133
134
    /**
135
     * @param boolean $ignoresTimeZone
136
     */
137
    public function setIgnoresTimeZone($ignoresTimeZone)
138
    {
139
        $this->ignoresTimeZone = $ignoresTimeZone;
140
141
        return $this;
142
    }
143
144
    /**
145
     * @return boolean
146
     */
147 1
    public function getIgnoresTimeZone()
148
    {
149 1
        return $this->ignoresTimeZone;
150
    }
151
152
    /**
153
     * @param boolean $isRelative
154
     */
155
    public function setIsRelative($isRelative)
156
    {
157
        $this->isRelative = $isRelative;
158
159
        return $this;
160
    }
161
162
    /**
163
     * @return boolean
164
     */
165 1
    public function getIsRelative()
166
    {
167 1
        return $this->isRelative;
168
    }
169
170
    /**
171
     * Must be one of PKDateStyle const
172
     * @param string $timeStyle
173
     */
174
    public function setTimeStyle($timeStyle)
175
    {
176
        $this->timeStyle = $timeStyle;
177
178
        return $this;
179
    }
180
181
    /**
182
     * @return string
183
     */
184 1
    public function getTimeStyle()
185
    {
186 1
        return (string) $this->timeStyle;
187
    }
188
189
    /**
190
     * Must be a ISO 8601 date string or a \DateTime object
191
     * @param string|\DateTime $value
192
     * @return $this
193
     */
194 1
    public function setValue($value)
195
    {
196 1
        if ($value instanceof \DateTime) {
197 1
            $value = $value->format('c');
198
        }
199
200 1
        return parent::setValue($value);
201
    }
202
}
203