Completed
Push — master ( cd5eb5...60c610 )
by WEBEWEB
08:13
created

NavigationItem   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 110
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getHref() 0 3 1
A getIcon() 0 3 1
A setHref() 0 4 1
A setIcon() 0 4 1
C toArray() 0 34 7
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
17
/**
18
 * Navigation item.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\BootstrapBundle\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 (null !== $this->href) {
106
            $output["href"] = $this->href;
107
        }
108
109
        // Check the icon.
110
        if (null !== $this->icon) {
111
            $output["icon"] = $this->icon;
112
        }
113
114
        // Check the span.
115
        if (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 (false === ($current instanceof NavigationItem)) {
124
                    continue;
125
                }
126
                $output["subitems"][] = $current->toArray();
127
            }
128
        }
129
130
        // Return the output.
131
        return $output;
132
    }
133
134
}
135