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

NavbarPresenter::getOpenTagWrapper()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace KyleMassacre\Menus\Presenters\Bootstrap;
4
5
use KyleMassacre\Menus\Contracts\MenuItemContract;
6
use KyleMassacre\Menus\Presenters\Presenter;
7
8
class NavbarPresenter extends Presenter
9
{
10
    /**
11
     * {@inheritdoc}
12 3
     */
13
    public function getOpenTagWrapper(): ?string
14 3
    {
15
        return PHP_EOL . '<ul class="nav navbar-nav">' . PHP_EOL;
16
    }
17
18
    /**
19
     * {@inheritdoc}
20 3
     */
21
    public function getCloseTagWrapper(): ?string
22 3
    {
23
        return PHP_EOL . '</ul>' . PHP_EOL;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getMenuWithoutDropdownWrapper(MenuItemContract $item): ?string
30
    {
31
        return '<li' . $this->getActiveState($item) . '><a href="' . $item->getUrl() . '" ' . $item->getAttributes() . '>' . $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

31
        return '<li' . $this->getActiveState($item) . '><a href="' . $item->getUrl() . '" ' . $item->getAttributes() . '>' . $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...
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getActiveState(MenuItemContract $item, string $state = ' class="active"'): ?string
38
    {
39
        return $item->isActive() ? $state : null;
40
    }
41
42
    /**
43
     * Get active state on child items.
44
     *
45
     * @param $item
46
     * @param string $state
47
     *
48
     * @return null|string
49
     */
50
    public function getActiveStateOnChild(MenuItemContract $item, string $state = 'active'): ?string
51
    {
52
        return $item->hasActiveOnChild() ? $state : null;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getDividerWrapper(): ?string
59
    {
60
        return '<li class="divider"></li>';
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function getHeaderWrapper(MenuItemContract $item): ?string
67
    {
68
        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...
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function getMenuWithDropDownWrapper(MenuItemContract $item): ?string
75
    {
76
        return '<li class="dropdown' . $this->getActiveStateOnChild($item, ' active') . '">
77
		          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
78
					' . $item->getIcon() . ' ' . $item->title . '
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

78
					' . $item->/** @scrutinizer ignore-call */ getIcon() . ' ' . $item->title . '

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...
79
			      	<b class="caret"></b>
80
			      </a>
81
			      <ul class="dropdown-menu">
82
			      	' . $this->getChildMenuItems($item) . '
83
			      </ul>
84
		      	</li>'
85
        . PHP_EOL;
86
    }
87
88
    /**
89
     * Get multilevel menu wrapper.
90
     *
91
     * @param MenuItemContract $item
92
     *
93
     * @return string
94
     */
95
    public function getMultiLevelDropdownWrapper(MenuItemContract $item): string
96
    {
97
        return '<li class="dropdown' . $this->getActiveStateOnChild($item, ' active') . '">
98
		          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
99
					' . $item->getIcon() . ' ' . $item->title . '
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

99
					' . $item->/** @scrutinizer ignore-call */ getIcon() . ' ' . $item->title . '

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...
100
			      	<b class="caret pull-right caret-right"></b>
101
			      </a>
102
			      <ul class="dropdown-menu">
103
			      	' . $this->getChildMenuItems($item) . '
104
			      </ul>
105
		      	</li>'
106
        . PHP_EOL;
107
    }
108
}
109