Completed
Push — master ( 0d9475...3c5d20 )
by WEBEWEB
01:25
created

NavigationItem::getHref()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 $span The span.
45
	 * @param string $icon The icon.
46
	 * @param string $href The href.
47
	 */
48
	public function __construct($span, $icon = null, $href = self::DEFAULT_HREF) {
49
		parent::__construct($span);
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
	 * Get the span.
74
	 *
75
	 * @return string Returns the span.
76
	 */
77
	public function getSpan() {
78
		return parent::getId();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getId() instead of getSpan()). Are you sure this is correct? If so, you might want to change this to $this->getId().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
79
	}
80
81
	/**
82
	 * Set the href.
83
	 *
84
	 * @param string $href The href.
85
	 * @return NavigationItem Returns the navigation item.
86
	 */
87
	public function setHref($href) {
88
		$this->href = $href;
89
		return $this;
90
	}
91
92
	/**
93
	 * Set the icon.
94
	 *
95
	 * @param string $icon The icon.
96
	 * @return NavigationItem Returns the navigation item.
97
	 */
98
	public function setIcon($icon) {
99
		$this->icon = $icon;
100
		return $this;
101
	}
102
103
	/**
104
	 * Convert into an array representing this instance.
105
	 *
106
	 * @return array Returns an array representing this instance.
107
	 */
108
	public function toArray() {
109
110
		// Initialize the output.
111
		$output = [];
112
113
		// Check the href.
114
		if (!is_null($this->href)) {
115
			$output["href"] = $this->href;
116
		}
117
118
		// Check the icon.
119
		if (!is_null($this->icon)) {
120
			$output["icon"] = $this->icon;
121
		}
122
123
		// Check the span.
124
		if (!is_null($this->getId())) {
125
			$output["span"] = $this->getId();
126
		}
127
128
		// Check the nodes.
129
		if (0 < $this->size()) {
130
			$output["subitems"] = [];
131
			foreach ($this->getNodes() as $current) {
132
				if ($current instanceof NavigationItem) {
133
					$output["subitems"][] = $current->toArray();
134
				}
135
			}
136
		}
137
138
		// Return the output.
139
		return $output;
140
	}
141
142
}
143