SidebarMenuPresenter::getActiveStateOnChild()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Nwidart\Menus\Presenters\Bootstrap;
4
5
use Illuminate\Support\Str;
6
use Nwidart\Menus\Presenters\Presenter;
7
8
class SidebarMenuPresenter extends Presenter
9
{
10
    /**
11
     * Get open tag wrapper.
12
     *
13
     * @return string
14
     */
15
    public function getOpenTagWrapper()
16
    {
17
        return '<ul class="nav navbar-nav">';
18
    }
19
20
    /**
21
     * Get close tag wrapper.
22
     *
23
     * @return string
24
     */
25
    public function getCloseTagWrapper()
26
    {
27
        return '</ul>';
28
    }
29
30
    /**
31
     * Get menu tag without dropdown wrapper.
32
     *
33
     * @param \Nwidart\Menus\MenuItem $item
34
     *
35
     * @return string
36
     */
37
    public function getMenuWithoutDropdownWrapper($item)
38
    {
39
        return '<li' . $this->getActiveState($item) . '>
40
			<a href="' . $item->getUrl() . '" ' . $item->getAttributes() . '>'
41
        . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
42
    }
43
44
    /**
45
     * {@inheritdoc }.
46
     */
47
    public function getActiveState($item, $state = ' class="active"')
48
    {
49
        return $item->isActive() ? $state : null;
50
    }
51
52
    /**
53
     * Get active state on child items.
54
     *
55
     * @param $item
56
     * @param string $state
57
     *
58
     * @return null|string
59
     */
60
    public function getActiveStateOnChild($item, $state = 'active')
61
    {
62
        return $item->hasActiveOnChild() ? $state : null;
63
    }
64
65
    /**
66
     * {@inheritdoc }.
67
     */
68
    public function getDividerWrapper()
69
    {
70
        return '<li class="divider"></li>';
71
    }
72
73
    /**
74
     * {@inheritdoc }.
75
     */
76
    public function getHeaderWrapper($item)
77
    {
78
        return '<li class="dropdown-header">' . $item->title . '</li>';
79
    }
80
81
    /**
82
     * {@inheritdoc }.
83
     */
84
    public function getMenuWithDropDownWrapper($item)
85
    {
86
        $id = Str::random();
87
88
        return '
89
		<li class="' . $this->getActiveStateOnChild($item) . ' panel panel-default" id="dropdown">
90
			<a data-toggle="collapse" href="#' . $id . '">
91
				' . $item->getIcon() . ' ' . $item->title . ' <span class="caret"></span>
92
			</a>
93
			<div id="' . $id . '" class="panel-collapse collapse ' . $this->getActiveStateOnChild($item, 'in') . '">
94
				<div class="panel-body">
95
					<ul class="nav navbar-nav">
96
						' . $this->getChildMenuItems($item) . '
97
					</ul>
98
				</div>
99
			</div>
100
		</li>
101
		' . PHP_EOL;
102
    }
103
104
    /**
105
     * Get multilevel menu wrapper.
106
     *
107
     * @param \Nwidart\Menus\MenuItem $item
108
     *
109
     * @return string`
0 ignored issues
show
Documentation introduced by
The doc-type string` could not be parsed: Unknown type name "string`" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
110
     */
111
    public function getMultiLevelDropdownWrapper($item)
112
    {
113
        return $this->getMenuWithDropDownWrapper($item);
114
    }
115
}
116