Completed
Push — 2.0 ( f56b08...046d46 )
by Nicolas
02:09
created

MenuPresenter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 89
Duplicated Lines 29.21 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 2
dl 26
loc 89
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getOpenTagWrapper() 0 4 1
A getCloseTagWrapper() 0 4 1
A getMenuWithoutDropdownWrapper() 0 4 1
A getActiveState() 0 8 3
A getActiveStateOnChild() 0 4 2
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 Modules\Menu\Presenters;
4
5
use Pingpong\Menus\MenuItem;
6
use Pingpong\Menus\Presenters\Presenter;
7
8
class MenuPresenter extends Presenter
9
{
10
    /**
11
     * {@inheritdoc }.
12
     */
13
    public function getOpenTagWrapper()
14
    {
15
        return PHP_EOL . '<ul class="nav navbar-nav">' . PHP_EOL;
16
    }
17
18
    /**
19
     * {@inheritdoc }.
20
     */
21
    public function getCloseTagWrapper()
22
    {
23
        return PHP_EOL . '</ul>' . PHP_EOL;
24
    }
25
26
    /**
27
     * {@inheritdoc }.
28
     */
29
    public function getMenuWithoutDropdownWrapper($item)
30
    {
31
        return '<li' . $this->getActiveState($item) . '><a href="' . $item->getUrl() . '" ' . $item->getAttributes() . '>' . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
32
    }
33
34
    /**
35
     * {@inheritdoc }.
36
     */
37
    public function getActiveState($item, $state = ' class="active"')
38
    {
39
        if (\LaravelLocalization::hideDefaultLocaleInURL() === false) {
40
            $item->url = locale() . '/' . preg_replace('%^/?' . locale() . '/%', '$1', $item->url);
41
        }
42
43
        return $item->isActive() ? $state : null;
44
    }
45
46
    /**
47
     * Get active state on child items.
48
     *
49
     * @param $item
50
     * @param string $state
51
     *
52
     * @return null|string
53
     */
54
    public function getActiveStateOnChild($item, $state = 'active')
55
    {
56
        return $item->hasActiveOnChild() ? $state : null;
57
    }
58
59
    /**
60
     * {@inheritdoc }.
61
     */
62 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...
63
    {
64
        return '<li class="dropdown' . $this->getActiveStateOnChild($item, ' active') . '">
65
		          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
66
					' . $item->getIcon() . ' ' . $item->title . '
67
			      	<b class="caret"></b>
68
			      </a>
69
			      <ul class="dropdown-menu">
70
			      	' . $this->getChildMenuItems($item) . '
71
			      </ul>
72
		      	</li>'
73
        . PHP_EOL;
74
    }
75
76
    /**
77
     * Get multilevel menu wrapper.
78
     *
79
     * @param MenuItem $item
80
     *
81
     * @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...
82
     */
83 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...
84
    {
85
        return '<li class="dropdown' . $this->getActiveStateOnChild($item, ' active') . '">
86
		          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
87
					' . $item->getIcon() . ' ' . $item->title . '
88
			      	<b class="caret pull-right caret-right"></b>
89
			      </a>
90
			      <ul class="dropdown-menu">
91
			      	' . $this->getChildMenuItems($item) . '
92
			      </ul>
93
		      	</li>'
94
        . PHP_EOL;
95
    }
96
}
97