Completed
Push — master ( 48b8fb...42c6a4 )
by WEBEWEB
02:20
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
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the bootstrap-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
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\Bundle\BootstrapBundle\Navigation\Item;
13
14
use WBW\Bundle\BootstrapBundle\Navigation\NavigationInterface;
15
use WBW\Library\Core\Node\AbstractNode;
16
use WBW\Library\Core\Utility\ArrayUtility;
17
18
/**
19
 * Navigation item.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Navigation\Item
23
 * @final
24
 * @deprecated
25
 */
26
final class NavigationItem extends AbstractNode implements NavigationInterface {
27
28
    /**
29
     * Href.
30
     *
31
     * @var string
32
     */
33
    private $href;
34
35
    /**
36
     * Icon.
37
     *
38
     * @var string
39
     */
40
    private $icon;
41
42
    /**
43
     * Constructor.
44
     *
45
     * @param string $id The id.
46
     * @param string $icon The icon.
47
     * @param string $href The href.
48
     */
49
    public function __construct($id, $icon = null, $href = self::DEFAULT_HREF) {
50
        parent::__construct($id);
51
        $this->icon = $icon;
52
        $this->href = $href;
53
    }
54
55
    /**
56
     * Get the href.
57
     *
58
     * @return string Returns the href.
59
     */
60
    public function getHref() {
61
        return $this->href;
62
    }
63
64
    /**
65
     * Get the icon.
66
     *
67
     * @return string Returns the icon.
68
     */
69
    public function getIcon() {
70
        return $this->icon;
71
    }
72
73
    /**
74
     * Set the href.
75
     *
76
     * @param string $href The href.
77
     * @return NavigationItem Returns the navigation item.
78
     */
79
    public function setHref($href) {
80
        $this->href = $href;
81
        return $this;
82
    }
83
84
    /**
85
     * Set the icon.
86
     *
87
     * @param string $icon The icon.
88
     * @return NavigationItem Returns the navigation item.
89
     */
90
    public function setIcon($icon) {
91
        $this->icon = $icon;
92
        return $this;
93
    }
94
95
    /**
96
     * Convert into an array representing this instance.
97
     *
98
     * @return array Returns an array representing this instance.
99
     */
100
    public function toArray() {
101
102
        // Initialize the output.
103
        $output = [];
104
105
        ArrayUtility::set($output, "href", $this->href, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
106
        ArrayUtility::set($output, "icon", $this->icon, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
107
        ArrayUtility::set($output, "span", $this->getId(), [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
109
        // Check the nodes.
110
        if (0 < $this->size()) {
111
            $output["subitems"] = [];
112
            foreach ($this->getNodes() as $current) {
113
                if (false === ($current instanceof NavigationItem)) {
114
                    continue;
115
                }
116
                $output["subitems"][] = $current->toArray();
117
            }
118
        }
119
120
        // Return the output.
121
        return $output;
122
    }
123
124
}
125