Passed
Pull Request — master (#57)
by Kyle
07:22
created

SidebarMenuPresenter::getCloseTagWrapper()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace KyleMassacre\Menus\Presenters\Bootstrap;
4
5
use Illuminate\Support\Str;
6
use KyleMassacre\Menus\Contracts\MenuItemContract;
7
use KyleMassacre\Menus\Presenters\Presenter;
8
9
class SidebarMenuPresenter extends Presenter
10
{
11
    /**
12
     * Get open tag wrapper.
13
     *
14
     * @return string
15
     */
16
    public function getOpenTagWrapper(): ?string
17
    {
18
        return '<ul class="nav navbar-nav">';
19
    }
20
21
    /**
22
     * Get close tag wrapper.
23
     *
24
     * @return string
25
     */
26
    public function getCloseTagWrapper(): ?string
27
    {
28
        return '</ul>';
29
    }
30
31
    /**
32
     * Get menu tag without dropdown wrapper.
33
     *
34
     * @param MenuItemContract $item
35
     *
36
     * @return string
37
     */
38
    public function getMenuWithoutDropdownWrapper(MenuItemContract $item): ?string
39
    {
40
        return '<li' . $this->getActiveState($item) . '>
41
			<a href="' . $item->getUrl() . '" ' . $item->getAttributes() . '>'
42
        . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
0 ignored issues
show
Bug introduced by
The call to KyleMassacre\Menus\Contr...ItemContract::getIcon() has too few arguments starting with default. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        . $item->/** @scrutinizer ignore-call */ getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug Best Practice introduced by
The property title does not exist on KyleMassacre\Menus\Contracts\MenuItemContract. Since you implemented __get, consider adding a @property annotation.
Loading history...
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getActiveState(MenuItemContract $item, string $state = ' class="active"'): mixed
49
    {
50
        return $item->isActive() ? $state : null;
51
    }
52
53
    /**
54
     * Get active state on child items.
55
     *
56
     * @param MenuItemContract $item
57
     * @param string $state
58
     *
59
     * @return null|string
60
     */
61
    public function getActiveStateOnChild(MenuItemContract $item, string $state = 'active'): ?string
62
    {
63
        return $item->hasActiveOnChild() ? $state : null;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getDividerWrapper(): ?string
70
    {
71
        return '<li class="divider"></li>';
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getHeaderWrapper(MenuItemContract $item): ?string
78
    {
79
        return '<li class="dropdown-header">' . $item->title . '</li>';
0 ignored issues
show
Bug Best Practice introduced by
The property title does not exist on KyleMassacre\Menus\Contracts\MenuItemContract. Since you implemented __get, consider adding a @property annotation.
Loading history...
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function getMenuWithDropDownWrapper(MenuItemContract $item): ?string
86
    {
87
        $id = Str::random();
88
89
        return '
90
		<li class="' . $this->getActiveStateOnChild($item) . ' panel panel-default" id="dropdown">
91
			<a data-toggle="collapse" href="#' . $id . '">
92
				' . $item->getIcon() . ' ' . $item->title . ' <span class="caret"></span>
0 ignored issues
show
Bug Best Practice introduced by
The property title does not exist on KyleMassacre\Menus\Contracts\MenuItemContract. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The call to KyleMassacre\Menus\Contr...ItemContract::getIcon() has too few arguments starting with default. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

92
				' . $item->/** @scrutinizer ignore-call */ getIcon() . ' ' . $item->title . ' <span class="caret"></span>

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
93
			</a>
94
			<div id="' . $id . '" class="panel-collapse collapse ' . $this->getActiveStateOnChild($item, 'in') . '">
95
				<div class="panel-body">
96
					<ul class="nav navbar-nav">
97
						' . $this->getChildMenuItems($item) . '
98
					</ul>
99
				</div>
100
			</div>
101
		</li>
102
		' . PHP_EOL;
103
    }
104
105
    /**
106
     * Get multilevel menu wrapper.
107
     *
108
     * @param MenuItemContract $item
109
     *
110
     * @return string
111
     */
112
    public function getMultiLevelDropdownWrapper(MenuItemContract $item): string
113
    {
114
        return $this->getMenuWithDropDownWrapper($item);
115
    }
116
}
117