Completed
Pull Request — master (#17)
by Nauris
10:18
created

NavbarPresenter::getDividerWrapper()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Nwidart\Menus\Presenters\Bootstrap;
4
5
use Nwidart\Menus\Presenters\Presenter;
6
7 View Code Duplication
class NavbarPresenter extends Presenter
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    /**
10
     * {@inheritdoc }.
11
     */
12 3
    public function getOpenTagWrapper()
13
    {
14 3
        return PHP_EOL . '<ul class="nav navbar-nav">' . PHP_EOL;
15
    }
16
17
    /**
18
     * {@inheritdoc }.
19
     */
20 3
    public function getCloseTagWrapper()
21
    {
22 3
        return PHP_EOL . '</ul>' . PHP_EOL;
23
    }
24
25
    /**
26
     * {@inheritdoc }.
27
     */
28
    public function getMenuWithoutDropdownWrapper($item)
29
    {
30
        if($item->auth && auth()->guest()) {
0 ignored issues
show
Bug introduced by
The method guest does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
31
            return null;
32
        }
33
34
        return '<li' . $this->getActiveState($item) . '><a href="' . $item->getUrl() . '" ' . $item->getAttributes() . '>' . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
35
    }
36
37
    /**
38
     * {@inheritdoc }.
39
     */
40
    public function getActiveState($item, $state = ' class="active"')
41
    {
42
        return $item->isActive() ? $state : null;
43
    }
44
45
    /**
46
     * Get active state on child items.
47
     *
48
     * @param $item
49
     * @param string $state
50
     *
51
     * @return null|string
52
     */
53
    public function getActiveStateOnChild($item, $state = 'active')
54
    {
55
        return $item->hasActiveOnChild() ? $state : null;
56
    }
57
58
    /**
59
     * {@inheritdoc }.
60
     */
61
    public function getDividerWrapper()
62
    {
63
        return '<li class="divider"></li>';
64
    }
65
66
    /**
67
     * {@inheritdoc }.
68
     */
69
    public function getHeaderWrapper($item)
70
    {
71
        return '<li class="dropdown-header">' . $item->title . '</li>';
72
    }
73
74
    /**
75
     * {@inheritdoc }.
76
     */
77
    public function getMenuWithDropDownWrapper($item)
78
    {
79
        if($item->auth && auth()->guest()) {
0 ignored issues
show
Bug introduced by
The method guest does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
80
            return null;
81
        }
82
83
        return '<li class="dropdown' . $this->getActiveStateOnChild($item, ' active') . '">
84
		          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
85
					' . $item->getIcon() . ' ' . $item->title . '
86
			      	<b class="caret"></b>
87
			      </a>
88
			      <ul class="dropdown-menu">
89
			      	' . $this->getChildMenuItems($item) . '
90
			      </ul>
91
		      	</li>'
92
        . PHP_EOL;
93
    }
94
95
    /**
96
     * Get multilevel menu wrapper.
97
     *
98
     * @param \Nwidart\Menus\MenuItem $item
99
     *
100
     * @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...
101
     */
102
    public function getMultiLevelDropdownWrapper($item)
103
    {
104
        if($item->auth && auth()->guest()) {
0 ignored issues
show
Bug introduced by
The method guest does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
105
            return null;
106
        }
107
108
        return '<li class="dropdown' . $this->getActiveStateOnChild($item, ' active') . '">
109
		          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
110
					' . $item->getIcon() . ' ' . $item->title . '
111
			      	<b class="caret pull-right caret-right"></b>
112
			      </a>
113
			      <ul class="dropdown-menu">
114
			      	' . $this->getChildMenuItems($item) . '
115
			      </ul>
116
		      	</li>'
117
        . PHP_EOL;
118
    }
119
}
120