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

Visibility   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 64.71%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 1
dl 0
loc 75
ccs 11
cts 17
cp 0.6471
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setPages() 0 6 1
A getPages() 0 4 1
A setCondition() 0 8 3
A getCondition() 0 4 1
A getEntityValue() 0 4 2
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