Completed
Pull Request — development (#3050)
by John
23:37
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
14
namespace ElkArte\Menu;
15
16
abstract class MenuItem
17
{
18
	/** @var string $label Text label for this subsection. */
19
	protected $label = '';
20
21
	/** @var string $counter Index of counter specified in the menu options. */
22
	protected $counter = '';
23
24
	/** @var string $url URL to use for this menu item. */
25
	protected $url = '';
26
27
	/** @var string[] $permission Array of permissions to check for this subsection. */
28
	protected $permission = [];
29
30
	/** @var bool $enabled Bool to say whether this should be enabled. */
31
	protected $enabled = true;
32
33
	/**
34
	 * @param array $arr
35
	 *
36
	 * @return MenuItem
37
	 */
38 41
	public static function buildFromArray(array $arr): MenuItem
39
	{
40 41
		$obj = new static;
41 41
		$arr['permission'] = isset($arr['permission']) ? (array) $arr['permission'] : [];
42 41
		$vars = get_object_vars($obj);
43 41
		foreach (array_replace(
44 41
					$vars,
45 41
					array_intersect_key($arr, $vars)
46
				) as $var => $val)
47
		{
48 41
			$obj->{'set' . ucfirst($var)}($val);
49
		}
50 41
		$obj->buildMoreFromArray($arr);
51
52 41
		return $obj;
53
	}
54
55
	/**
56
	 * @return string
57
	 */
58 38
	public function getLabel(): string
59
	{
60 38
		return $this->label;
61
	}
62
63
	/**
64
	 * @param string $label
65
	 *
66
	 * @return MenuItem
67
	 */
68 41
	public function setLabel(string $label): MenuItem
69
	{
70 41
		$this->label = $label;
71
72 41
		return $this;
73
	}
74
75
	/**
76
	 * @return string
77
	 */
78 38
	public function getCounter(): string
79
	{
80 38
		return $this->counter;
81
	}
82
83
	/**
84
	 * @param string $counter
85
	 *
86
	 * @return MenuItem
87
	 */
88 41
	public function setCounter(string $counter): MenuItem
89
	{
90 41
		$this->counter = $counter;
91
92 41
		return $this;
93
	}
94
95
	/**
96
	 * @return string
97
	 */
98 38
	public function getUrl(): string
99
	{
100 38
		return $this->url;
101
	}
102
103
	/**
104
	 * @param string $url
105
	 *
106
	 * @return MenuItem
107
	 */
108 41
	public function setUrl(string $url): MenuItem
109
	{
110 41
		$this->url = $url;
111
112 41
		return $this;
113
	}
114
115
	/**
116
	 * @return string[]
117
	 */
118 39
	public function getPermission(): array
119
	{
120 39
		return $this->permission;
121
	}
122
123
	/**
124
	 * @param string[] $permission
125
	 *
126
	 * @return MenuItem
127
	 */
128 41
	public function setPermission(array $permission): MenuItem
129
	{
130 41
		$this->permission = $permission;
131
132 41
		return $this;
133
	}
134
135
	/**
136
	 * @return boolean
137
	 */
138 39
	public function isEnabled(): bool
139
	{
140 39
		return $this->enabled;
141
	}
142
143
	/**
144
	 * @param boolean $enabled
145
	 *
146
	 * @return MenuItem
147
	 */
148 41
	public function setEnabled(bool $enabled): MenuItem
149
	{
150 41
		$this->enabled = $enabled;
151
152 41
		return $this;
153
	}
154
}
155