Completed
Push — master ( ee772b...eafbd1 )
by
unknown
04:02
created

Rule::getPriority()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Acquia\LiftClient\Entity;
4
5
use Acquia\LiftClient\Exception\LiftSdkException;
6
use DateTime;
7
8
class Rule extends Entity
9
{
10
    /**
11
     * @param array $array
12
     */
13 84
    public function __construct(array $array = [])
14
    {
15 84
        parent::__construct($array);
16 84
    }
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\Rule
26
     */
27 33
    public function setId($id)
28
    {
29 33
        if (!is_string($id)) {
30 3
            throw new LiftSdkException('Argument must be an instance of string.');
31
        }
32 30
        $this['id'] = $id;
33
34 30
        return $this;
35
    }
36
37
    /**
38
     * Gets the 'id' parameter.
39
     *
40
     * @return string The Identifier of the Rule
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\Rule
55
     */
56 33
    public function setLabel($label)
57
    {
58 33
        if (!is_string($label)) {
59 3
            throw new LiftSdkException('Argument must be an instance of string.');
60
        }
61 30
        $this['label'] = $label;
62
63 30
        return $this;
64
    }
65
66
    /**
67
     * Gets the 'label' 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\Rule
84
     */
85 33
    public function setDescription($description)
86
    {
87 33
        if (!is_string($description)) {
88 3
            throw new LiftSdkException('Argument must be an instance of string.');
89
        }
90 30
        $this['description'] = $description;
91
92 30
        return $this;
93
    }
94
95
    /**
96
     * Gets the 'description' parameter.
97
     *
98
     * @return string The Description of the Rule
99
     */
100 12
    public function getDescription()
101
    {
102 12
        return $this->getEntityValue('description', '');
103
    }
104
105
    /**
106
     * Sets the 'slot_id' parameter.
107
     *
108
     * @param string $slotId
109
     *
110
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
111
     *
112
     * @return \Acquia\LiftClient\Entity\Rule
113
     */
114 33
    public function setSlotId($slotId)
115
    {
116 33
        if (!is_string($slotId)) {
117 3
            throw new LiftSdkException('Argument must be an instance of string.');
118
        }
119 30
        $this['slot_id'] = $slotId;
120
121 30
        return $this;
122
    }
123
124
    /**
125
     * Gets the 'slot_id' parameter.
126
     *
127
     * @return string The Description of the Rule
128
     */
129 12
    public function getSlotId()
130
    {
131 12
        return $this->getEntityValue('slot_id', '');
132
    }
133
134
    /**
135
     * Sets the 'priority' parameter.
136
     *
137
     * @param int $priority
138
     *
139
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
140
     *
141
     * @return \Acquia\LiftClient\Entity\Rule
142
     */
143 33
    public function setPriority($priority)
144
    {
145 33
        if (!is_integer($priority)) {
146 3
            throw new LiftSdkException('Argument must be an instance of integer.');
147
        }
148 30
        $this['priority'] = $priority;
149
150 30
        return $this;
151
    }
152
153
    /**
154
     * Gets the 'priority' parameter.
155
     *
156
     * @return int The priority of the Rule
157
     */
158 12
    public function getPriority()
159
    {
160 12
        return $this->getEntityValue('priority', 0);
161
    }
162
163
    /**
164
     * Sets the 'weight' parameter.
165
     *
166
     * @deprecated use the priority parameter instead.
167
     * @param int $weight
168
     *
169
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
170
     *
171
     * @return \Acquia\LiftClient\Entity\Rule
172
     */
173
    public function setWeight($weight)
174
    {
175
        return $this->setPriority($weight);
176
    }
177
178
    /**
179
     * Gets the 'weight' parameter.
180
     *
181
     * @deprecated use the priority parameter instead.
182
     * @return int The weight of the Rule
183
     */
184
    public function getWeight()
185
    {
186
        return $this->getPriority();
187
    }
188
189
    /**
190
     * Sets the 'content' parameter.
191
     *
192
     * @param Content[] $contentList
193
     *
194
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
195
     *
196
     * @return \Acquia\LiftClient\Entity\Rule
197
     */
198 30
    public function setContentList(array $contentList)
199
    {
200 30
        $this['content'] = [];
201 30
        foreach ($contentList as $content) {
202
            // We need to 'normalize' the data.
203 30
            $this['content'][] = $content->getArrayCopy();
204 20
        }
205
206 30
        return $this;
207
    }
208
209
    /**
210
     * Gets the 'content' parameter.
211
     *
212
     * @return Content[] The list of content this rule applies to
213
     */
214 12
    public function getContentList()
215
    {
216 12
        $contentList = $this->getEntityValue('content', '');
217 12
        $ret = [];
218 12
        foreach ($contentList as $content) {
219 12
            $ret[] = new Content($content);
220 8
        }
221
222 12
        return $ret;
223
    }
224
225
    /**
226
     * Sets the 'segment' parameter.
227
     *
228
     * @param string $segment
229
     *
230
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
231
     *
232
     * @return \Acquia\LiftClient\Entity\Rule
233
     */
234 33
    public function setSegmentId($segment)
235
    {
236 33
        if (!is_string($segment)) {
237 3
            throw new LiftSdkException('Argument must be an instance of string.');
238
        }
239 30
        $this['segment'] = $segment;
240
241 30
        return $this;
242
    }
243
244
    /**
245
     * Gets the 'segment' parameter.
246
     *
247
     * @return string
248
     */
249 12
    public function getSegmentId()
250
    {
251 12
        return $this->getEntityValue('segment', '');
252
    }
253
254
    /**
255
     * Sets the 'status' parameter.
256
     *
257
     * @param string $status
258
     *
259
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
260
     *
261
     * @return \Acquia\LiftClient\Entity\Rule
262
     */
263 36
    public function setStatus($status)
264
    {
265 36
        if (!is_string($status)) {
266 3
            throw new LiftSdkException('Argument must be an instance of string.');
267
        }
268 33
        if ($status !== 'published' && $status !== 'unpublished' && $status !== 'archived') {
269 3
            throw new LiftSdkException('Status much be either published, unpublished or archived.');
270
        }
271 30
        $this['status'] = $status;
272
273 30
        return $this;
274
    }
275
276
    /**
277
     * Gets the 'status' parameter.
278
     *
279
     * @return string
280
     */
281 12
    public function getStatus()
282
    {
283 12
        return $this->getEntityValue('status', '');
284
    }
285
286
    /**
287
     * Gets the 'created' parameter.
288
     *
289
     * @return DateTime|false
290
     */
291 12
    public function getCreated()
292
    {
293 12
        $date = $this->getEntityValue('created', 0);
294
        // The ISO8601 DateTime format is not compatible with ISO-8601, but is left this way for backward compatibility
295
        // reasons. Use DateTime::ATOM or DATE_ATOM for compatibility with ISO-8601 instead.
296
        // See http://php.net/manual/en/class.datetime.php
297 12
        $datetime = DateTime::createFromFormat(DateTime::ATOM, $date);
298
299 12
        return $datetime;
300
    }
301
302
    /**
303
     * Gets the 'updated' parameter.
304
     *
305
     * @return DateTime|false
306
     */
307 12
    public function getUpdated()
308
    {
309 12
        $date = $this->getEntityValue('updated', 0);
310
        // The ISO8601 DateTime format is not compatible with ISO-8601, but is left this way for backward compatibility
311
        // reasons. Use DateTime::ATOM or DATE_ATOM for compatibility with ISO-8601 instead.
312
        // See http://php.net/manual/en/class.datetime.php
313 12
        $datetime = DateTime::createFromFormat(DateTime::ATOM, $date);
314
315 12
        return $datetime;
316
    }
317
318
    /**
319
     * Sets the Rule test_config property.
320
     *
321
     * @param \Acquia\LiftClient\Entity\TestConfigInterface $testConfig
322
     *
323
     * @return \Acquia\LiftClient\Entity\Rule
324
     */
325 30
    public function setTestConfig(TestConfigInterface $testConfig)
326
    {
327
        // To facilitate TypeHinting in PHPStorm we redefine what $testConfig is
328
        // here. We know it inherits from the TestConfigInterface and is a child
329
        // of TestConfigBase.
330
        /** @var \Acquia\LiftClient\Entity\TestConfigBase $testConfig */
331
332
        // Get class of the testConfig object.
333 30
        $type = get_class($testConfig);
334
335
        // Only allow one test type at a time.
336 30
        $this['testconfig'] = [];
337
        switch ($type) {
338 30
            case 'Acquia\LiftClient\Entity\TestConfigAb':
339 30
                $this['testconfig']['ab'] = $testConfig->getArrayCopy();
340 30
                break;
341 3
            case 'Acquia\LiftClient\Entity\TestConfigMab':
342 3
                $this['testconfig']['mab'] = $testConfig->getArrayCopy();
343 3
                break;
344 3
            case 'Acquia\LiftClient\Entity\TestConfigTarget':
345 3
                $this['testconfig']['target'] = $testConfig->getArrayCopy();
346 3
                break;
347
        }
348
349 30
        return $this;
350
    }
351
352
    /**
353
     * Gets the 'test_config' parameter.
354
     *
355
     * @return \Acquia\LiftClient\Entity\TestConfigInterface|null $testConfig
356
     */
357 12
    public function getTestConfig()
358
    {
359 12
        $testConfig = $this->getEntityValue('testconfig', []);
360
        // We know the array only has one possible set of options.
361
        // Get its key and value.
362 12
        reset($testConfig);
363 12
        $key = key($testConfig);
364
365
        // Based on the config, we load the different objects.
366
        switch ($key) {
367 12
            case 'ab':
368 12
                return new TestConfigAb($testConfig[$key]);
369
            case 'mab':
370
                return new TestConfigMab($testConfig[$key]);
371
            case 'target':
372
                return new TestConfigTarget($testConfig[$key]);
373
        }
374
375
        return null;
376
    }
377
}
378