Completed
Pull Request — master (#4)
by Nick
05:39
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
19
     *   Specify pages by using their paths. The '*' character is a wildcard.
20
     *   Example paths are 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
44
     *   Sets the condition of this visibility object. Can be 'show' or 'hide'.
45
     *   Any other option will be ignored.
46
     *
47
     * @return \Acquia\LiftClient\Entity\Visibility
48
     */
49 12
    public function setCondition($condition)
50
    {
51 12
        if ($condition === 'show' || $condition === 'hide') {
52 12
            $this['condition'] = $condition;
53 8
        }
54
55 12
        return $this;
56
    }
57
58
    /**
59
     * Gets the 'condition' parameter.
60
     *
61
     * @return array
62
     */
63
    public function getCondition()
64
    {
65
        return $this->getEntityValue('condition', '');
66
    }
67
68
    /**
69
     *
70
     * @param string $key
71
     * @param string $default
72
     *
73
     * @return mixed
74
     */
75
    protected function getEntityValue($key, $default)
76
    {
77
        return isset($this[$key]) ? $this[$key] : $default;
78
    }
79
}
80