Completed
Pull Request — master (#28)
by
unknown
08:18
created

Slot::setCssSelector()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 7
cp 0.8571
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0116
1
<?php
2
3
namespace Acquia\LiftClient\Entity;
4
5
use Acquia\LiftClient\Exception\LiftSdkException;
6
use DateTime;
7
8
class Slot extends Entity
9
{
10
    /**
11
     * @param array $array
12
     */
13 45
    public function __construct(array $array = [])
14
    {
15 45
        parent::__construct($array);
16 45
    }
17
18
    /**
19
     * Sets the 'id' parameter.
20
     *
21
     * @param string $id
22
     *
23
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
24
     *
25
     * @return \Acquia\LiftClient\Entity\Slot
26
     */
27 12
    public function setId($id)
28
    {
29 12
        if (!is_string($id)) {
30 3
            throw new LiftSdkException('Argument must be an instance of string.');
31
        }
32 9
        $this['id'] = $id;
33
34 9
        return $this;
35
    }
36
37
    /**
38
     * Gets the 'id' parameter.
39
     *
40
     * @return string
41
     */
42 12
    public function getId()
43
    {
44 12
        return $this->getEntityValue('id', '');
45
    }
46
47
    /**
48
     * Sets the 'label' parameter.
49
     *
50
     * @param string $label
51
     *
52
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
53
     *
54
     * @return \Acquia\LiftClient\Entity\Slot
55
     */
56 12
    public function setLabel($label)
57
    {
58 12
        if (!is_string($label)) {
59 3
            throw new LiftSdkException('Argument must be an instance of string.');
60
        }
61 9
        $this['label'] = $label;
62
63 9
        return $this;
64
    }
65
66
    /**
67
     * Gets the 'id' parameter.
68
     *
69
     * @return string
70
     */
71 12
    public function getLabel()
72
    {
73 12
        return $this->getEntityValue('label', '');
74
    }
75
76
    /**
77
     * Sets the 'description' parameter.
78
     *
79
     * @param string $description
80
     *
81
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
82
     *
83
     * @return \Acquia\LiftClient\Entity\Slot
84
     */
85 12
    public function setDescription($description)
86
    {
87 12
        if (!is_string($description)) {
88 3
            throw new LiftSdkException('Argument must be an instance of string.');
89
        }
90 9
        $this['description'] = $description;
91
92 9
        return $this;
93
    }
94
95
    /**
96
     * Gets the 'description' parameter.
97
     *
98
     * @return string
99
     */
100 12
    public function getDescription()
101
    {
102 12
        return $this->getEntityValue('description', '');
103
    }
104
105
    /**
106
     * Sets the 'css_selector' parameter.
107
     *
108
     * @param string $css_selector
109
     *
110
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
111
     *
112
     * @return \Acquia\LiftClient\Entity\Slot
113
     */
114 12
    public function setCssSelector($css_selector)
115
    {
116 12
      if (!is_string($css_selector)) {
117 3
        throw new LiftSdkException('Argument must be an instance of string.');
118
      }
119 9
      $this['css_selector'] = $css_selector;
120 9
121 6
      return $this;
122
    }
123
124
    /**
125 9
     * Gets the 'css_selector' parameter.
126
     *
127
     * @return string
128
     */
129
    public function getCssSelector()
130
    {
131
      return $this->getEntityValue('css_selector', '');
132
    }
133 12
134
135 12
    /**
136 12
     * Sets the 'status' parameter.
137 12
     *
138
     * @param bool $status
139
     *
140
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
141
     *
142
     * @return \Acquia\LiftClient\Entity\Slot
143
     */
144
    public function setStatus($status)
145
    {
146
        if (!is_bool($status)) {
147
            throw new LiftSdkException('Argument must be an instance of boolean.');
148
        }
149
        if ($status) {
150 9
            $this['status'] = 'enabled';
151
        } else {
152
            $this['status'] = 'disabled';
153 9
        }
154
155 9
        return $this;
156
    }
157
158
    /**
159
     * Gets the 'status' parameter. True if the slot is published. False is it is not.
160
     *
161
     * @return bool
162
     */
163 12
    public function getStatus()
164
    {
165 12
        $status = $this->getEntityValue('status', '');
166
        if ($status == 'enabled') {
167 12
            return true;
168
        }
169
170
        return false;
171
    }
172
173
    /**
174
     * Sets the 'visibility' parameter.
175 12
     *
176
     * @param \Acquia\LiftClient\Entity\Visibility $visibility
177 12
     *
178
     * @return \Acquia\LiftClient\Entity\Slot
179
     */
180
    public function setVisibility(Visibility $visibility)
181 12
    {
182
        // We need to 'normalize' the data.
183 12
        $this['visibility'] = $visibility->getArrayCopy();
184
185
        return $this;
186
    }
187
188
    /**
189
     * Gets the 'visibility' parameter.
190
     *
191 12
     * @return Visibility
192
     */
193 12
    public function getVisibility()
194
    {
195
        $visibility = $this->getEntityValue('visibility', []);
196
197 12
        return new Visibility($visibility);
198
    }
199 12
200
    /**
201
     * Gets the 'created' parameter.
202
     *
203
     * @return DateTime|false
204
     */
205
    public function getCreated()
206
    {
207
        $date = $this->getEntityValue('created', '');
208
        // The ISO8601 DateTime format is not compatible with ISO-8601, but is left this way for backward compatibility
209
        // reasons. Use DateTime::ATOM or DATE_ATOM for compatibility with ISO-8601 instead.
210
        // See http://php.net/manual/en/class.datetime.php
211
        $datetime = DateTime::createFromFormat(DateTime::ATOM, $date);
212
213
        return $datetime;
214
    }
215
216
    /**
217
     * Gets the 'updated' parameter.
218
     *
219
     * @return DateTime|false
220
     */
221
    public function getUpdated()
222
    {
223
        $date = $this->getEntityValue('updated', '');
224
        // The ISO8601 DateTime format is not compatible with ISO-8601, but is left this way for backward compatibility
225
        // reasons. Use DateTime::ATOM or DATE_ATOM for compatibility with ISO-8601 instead.
226
        // See http://php.net/manual/en/class.datetime.php
227
        $datetime = DateTime::createFromFormat(DateTime::ATOM, $date);
228
229
        return $datetime;
230
    }
231
}
232