Completed
Push — master ( 494359...c0981b )
by WEBEWEB
01:47
created

NavigationItem::setIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2017 NdC/WBW
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\Navigation\Item;
13
14
use WBW\Library\Core\Navigation\NavigationInterface;
15
use WBW\Library\Core\Node\AbstractNode;
16
17
/**
18
 * Navigation item.
19
 *
20
 * @author NdC/WBW <https://github.com/webeweb/>
21
 * @package WBW\Library\Core\Navigation\Item
22
 * @final
23
 * @deprecated
24
 */
25
final class NavigationItem extends AbstractNode implements NavigationInterface {
26
27
	/**
28
	 * Href.
29
	 *
30
	 * @var string
31
	 */
32
	private $href;
33
34
	/**
35
	 * Icon.
36
	 *
37
	 * @var string
38
	 */
39
	private $icon;
40
41
	/**
42
	 * Constructor.
43
	 *
44
	 * @param string $id The id.
45
	 * @param string $icon The icon.
46
	 * @param string $href The href.
47
	 */
48
	public function __construct($id, $icon = null, $href = self::DEFAULT_HREF) {
49
		parent::__construct($id);
50
		$this->icon	 = $icon;
51
		$this->href	 = $href;
52
	}
53
54
	/**
55
	 * Get the href.
56
	 *
57
	 * @return string Returns the href.
58
	 */
59
	public function getHref() {
60
		return $this->href;
61
	}
62
63
	/**
64
	 * Get the icon.
65
	 *
66
	 * @return string Returns the icon.
67
	 */
68
	public function getIcon() {
69
		return $this->icon;
70
	}
71
72
	/**
73
	 * Set the href.
74
	 *
75
	 * @param string $href The href.
76
	 * @return NavigationItem Returns the navigation item.
77
	 */
78
	public function setHref($href) {
79
		$this->href = $href;
80
		return $this;
81
	}
82
83
	/**
84
	 * Set the icon.
85
	 *
86
	 * @param string $icon The icon.
87
	 * @return NavigationItem Returns the navigation item.
88
	 */
89
	public function setIcon($icon) {
90
		$this->icon = $icon;
91
		return $this;
92
	}
93
94
	/**
95
	 * Convert into an array representing this instance.
96
	 *
97
	 * @return array Returns an array representing this instance.
98
	 */
99
	public function toArray() {
100
101
		// Initialize the output.
102
		$output = [];
103
104
		// Check the href.
105
		if (!is_null($this->href)) {
106
			$output["href"] = $this->href;
107
		}
108
109
		// Check the icon.
110
		if (!is_null($this->icon)) {
111
			$output["icon"] = $this->icon;
112
		}
113
114
		// Check the span.
115
		if (!is_null($this->getId())) {
116
			$output["span"] = $this->getId();
117
		}
118
119
		// Check the nodes.
120
		if (0 < $this->size()) {
121
			$output["subitems"] = [];
122
			foreach ($this->getNodes() as $current) {
123
				if (($current instanceof NavigationItem) === false) {
124
					continue;
125
				}
126
				$output["subitems"][] = $current->toArray();
127
			}
128
		}
129
130
		// Return the output.
131
		return $output;
132
	}
133
134
}
135