Completed
Push — master ( 5e1e13...f15dc3 )
by Nicolas
03:21
created

NavbarPresenter   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 101
Duplicated Lines 25.74 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 15.38%

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 1
cbo 2
dl 26
loc 101
ccs 4
cts 26
cp 0.1538
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getOpenTagWrapper() 0 4 1
A getCloseTagWrapper() 0 4 1
A getMenuWithoutDropdownWrapper() 0 4 1
A getActiveState() 0 4 2
A getActiveStateOnChild() 0 4 2
A getDividerWrapper() 0 4 1
A getHeaderWrapper() 0 4 1
A getMenuWithDropDownWrapper() 13 13 1
A getMultiLevelDropdownWrapper() 13 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Nwidart\Menus\Presenters\Bootstrap;
4
5
use Nwidart\Menus\Presenters\Presenter;
6
7
class NavbarPresenter extends Presenter
8
{
9
    /**
10
     * {@inheritdoc }.
11
     */
12 1
    public function getOpenTagWrapper()
13
    {
14 1
        return PHP_EOL . '<ul class="nav navbar-nav">' . PHP_EOL;
15
    }
16
17
    /**
18
     * {@inheritdoc }.
19
     */
20 1
    public function getCloseTagWrapper()
21
    {
22 1
        return PHP_EOL . '</ul>' . PHP_EOL;
23
    }
24
25
    /**
26
     * {@inheritdoc }.
27
     */
28
    public function getMenuWithoutDropdownWrapper($item)
29
    {
30
        return '<li' . $this->getActiveState($item) . '><a href="' . $item->getUrl() . '" ' . $item->getAttributes() . '>' . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<Nwidart\Menus\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
31
    }
32
33
    /**
34
     * {@inheritdoc }.
35
     */
36
    public function getActiveState($item, $state = ' class="active"')
37
    {
38
        return $item->isActive() ? $state : null;
39
    }
40
41
    /**
42
     * Get active state on child items.
43
     *
44
     * @param $item
45
     * @param string $state
46
     *
47
     * @return null|string
48
     */
49
    public function getActiveStateOnChild($item, $state = 'active')
50
    {
51
        return $item->hasActiveOnChild() ? $state : null;
52
    }
53
54
    /**
55
     * {@inheritdoc }.
56
     */
57
    public function getDividerWrapper()
58
    {
59
        return '<li class="divider"></li>';
60
    }
61
62
    /**
63
     * {@inheritdoc }.
64
     */
65
    public function getHeaderWrapper($item)
66
    {
67
        return '<li class="dropdown-header">' . $item->title . '</li>';
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<Nwidart\Menus\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
68
    }
69
70
    /**
71
     * {@inheritdoc }.
72
     */
73 View Code Duplication
    public function getMenuWithDropDownWrapper($item)
0 ignored issues
show
Duplication introduced by
This method 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...
74
    {
75
        return '<li class="dropdown' . $this->getActiveStateOnChild($item, ' active') . '">
76
		          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
77
					' . $item->getIcon() . ' ' . $item->title . '
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<Nwidart\Menus\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
78
			      	<b class="caret"></b>
79
			      </a>
80
			      <ul class="dropdown-menu">
81
			      	' . $this->getChildMenuItems($item) . '
82
			      </ul>
83
		      	</li>'
84
        . PHP_EOL;
85
    }
86
87
    /**
88
     * Get multilevel menu wrapper.
89
     *
90
     * @param \Nwidart\Menus\MenuItem $item
91
     *
92
     * @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...
93
     */
94 View Code Duplication
    public function getMultiLevelDropdownWrapper($item)
0 ignored issues
show
Duplication introduced by
This method 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...
95
    {
96
        return '<li class="dropdown' . $this->getActiveStateOnChild($item, ' active') . '">
97
		          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
98
					' . $item->getIcon() . ' ' . $item->title . '
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<Nwidart\Menus\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

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