Completed
Pull Request — development (#3050)
by John
09:17
created

MenuItem::getPermission()   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
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This class contains a standard way of displaying side/drop down menus.
5
 *
6
 * @name      ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
9
 *
10
 * @version   2.0 dev
11
 */
12
13
namespace ElkArte\Menu;
14
15
/**
16
 * Class MenuItem
17
 *
18
 * This class implements a standard way of creating menus
19
 *
20
 * @package ElkArte\Menu
21
 */
22
abstract class MenuItem
23
{
24
	/** @var string $label Text label for this subsection. */
25
	protected $label = '';
26
27
	/** @var string $counter Index of counter specified in the menu options. */
28
	protected $counter = '';
29
30
	/** @var string $url URL to use for this menu item. */
31
	protected $url = '';
32
33
	/** @var string[] $permission Array of permissions to check for this subsection. */
34
	protected $permission = [];
35
36
	/** @var bool $enabled Bool to say whether this should be enabled. */
37
	protected $enabled = true;
38
39
	/**
40
	 * @param array $arr
41
	 *
42
	 * @return MenuItem
43
	 */
44 41
	public static function buildFromArray(array $arr): MenuItem
45
	{
46 41
		$obj = new static;
47 41
		$arr['permission'] = isset($arr['permission']) ? (array) $arr['permission'] : [];
48 41
		$vars = get_object_vars($obj);
49 41
		foreach (array_replace(
50 41
					$vars,
51 41
					array_intersect_key($arr, $vars)
52
				) as $var => $val)
53
		{
54 41
			$obj->{'set' . ucfirst($var)}($val);
55
		}
56 41
		$obj->buildMoreFromArray($arr);
57
58 41
		return $obj;
59
	}
60
61
	/**
62
	 * @return string
63
	 */
64 38
	public function getLabel(): string
65
	{
66 38
		return $this->label;
67
	}
68
69
	/**
70
	 * @param string $label
71
	 *
72
	 * @return MenuItem
73
	 */
74 41
	public function setLabel(string $label): MenuItem
75
	{
76 41
		$this->label = $label;
77
78 41
		return $this;
79
	}
80
81
	/**
82
	 * @return string
83
	 */
84 38
	public function getCounter(): string
85
	{
86 38
		return $this->counter;
87
	}
88
89
	/**
90
	 * @param string $counter
91
	 *
92
	 * @return MenuItem
93
	 */
94 41
	public function setCounter(string $counter): MenuItem
95
	{
96 41
		$this->counter = $counter;
97
98 41
		return $this;
99
	}
100
101
	/**
102
	 * @return string
103
	 */
104 38
	public function getUrl(): string
105
	{
106 38
		return $this->url;
107
	}
108
109
	/**
110
	 * @param string $url
111
	 *
112
	 * @return MenuItem
113
	 */
114 41
	public function setUrl(string $url): MenuItem
115
	{
116 41
		$this->url = $url;
117
118 41
		return $this;
119
	}
120
121
	/**
122
	 * @return string[]
123
	 */
124 39
	public function getPermission(): array
125
	{
126 39
		return $this->permission;
127
	}
128
129
	/**
130
	 * @param string[] $permission
131
	 *
132
	 * @return MenuItem
133
	 */
134 41
	public function setPermission(array $permission): MenuItem
135
	{
136 41
		$this->permission = $permission;
137
138 41
		return $this;
139
	}
140
141
	/**
142
	 * @return boolean
143
	 */
144 39
	public function isEnabled(): bool
145
	{
146 39
		return $this->enabled;
147
	}
148
149
	/**
150
	 * @param boolean $enabled
151
	 *
152
	 * @return MenuItem
153
	 */
154 41
	public function setEnabled(bool $enabled): MenuItem
155
	{
156 41
		$this->enabled = $enabled;
157
158 41
		return $this;
159
	}
160
}
161