Completed
Pull Request — master (#4)
by Nick
03:05
created

Visibility::getEntityValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Acquia\LiftClient\Entity;
4
5
class Visibility extends \ArrayObject
6
{
7
    use EntityValueTrait;
8
9
    /**
10
     * @param array $array
11
     */
12 12
    public function __construct(array $array = [])
13
    {
14 12
        parent::__construct($array);
15 12
    }
16
17
    /**
18
     * @param array $pages Specify pages by using their paths. The '*' character
19
     *                     is a wildcard. Example paths are
20
     *                     http://mywebsite.com/user for the current user's page
21
     *                     and http://mywebsite.com/user/* for every user page
22
     *
23
     * @return \Acquia\LiftClient\Entity\Visibility
24
     */
25 12
    public function setPages(array $pages = [])
26
    {
27 12
        $this['pages'] = $pages;
28
29 12
        return $this;
30
    }
31
32
    /**
33
     * Gets the 'pages' parameter.
34
     *
35
     * @return array
36
     */
37
    public function getPages()
38
    {
39
        return $this->getEntityValue('pages', '');
40
    }
41
42
    /**
43
     * @param string $condition Can be 'show' or 'hide'. Any other option will
44
     *                          be ignored
45
     *
46
     * @return \Acquia\LiftClient\Entity\Visibility
47
     */
48 12
    public function setCondition($condition)
49
    {
50 12
        if ($condition === 'show' || $condition === 'hide') {
51 12
            $this['condition'] = $condition;
52 8
        }
53
54 12
        return $this;
55
    }
56
57
    /**
58
     * Gets the 'condition' parameter.
59
     *
60
     * @return array
61
     */
62
    public function getCondition()
63
    {
64
        return $this->getEntityValue('condition', '');
65
    }
66
67
    /**
68
     * @param string $key
69
     * @param string $default
70
     *
71
     * @return mixed
72
     */
73
    protected function getEntityValue($key, $default)
74
    {
75
        return isset($this[$key]) ? $this[$key] : $default;
76
    }
77
}
78