Top_Bar_Walker   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 11.86 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 7
loc 59
rs 10
c 0
b 0
f 0
wmc 10
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A display_element() 7 7 5
A start_el() 0 22 4
A start_lvl() 0 4 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
// Oenu walker for top bar
4
/**
5
 * @param $element
6
 * @param $children_elements
7
 * @param $max_depth
8
 * @param $depth
9
 * @param $args
10
 * @param $output
11
 */
12
final class Top_Bar_Walker extends Walker_Nav_Menu
13
{
14
    /**
15
     * @param $element
16
     * @param $children_elements
17
     * @param $max_depth
18
     * @param $depth
19
     * @param $args
20
     * @param $output
21
     */
22 View Code Duplication
    public function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output)
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...
23
    {
24
        $element->has_children = !empty($children_elements[$element->ID]);
25
        $element->classes[]    = ($element->current || $element->current_item_ancestor) ? 'active' : '';
26
        $element->classes[]    = ($element->has_children && 1 !== $max_depth) ? 'has-submenu' : '';
27
        parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
28
    }
29
30
    /**
31
     * @param $output
32
     * @param $object
33
     * @param $depth
34
     * @param array                $args
35
     * @param $current_object_id
36
     */
37
    public function start_el(&$output, $object, $depth = 0, $args = [], $current_object_id = 0)
38
    {
39
        $item_html = '';
40
        parent::start_el($item_html, $object, $depth, $args);
41
        //$output .= ( 0 == $depth ) ? '<li class="divider"></li>' : '';
42
        $classes = empty($object->classes) ? [] : (array) $object->classes;
43
44
        if (in_array('label', $classes)) {
45
46
            //$output .= '<li class="divider"></li>';
47
            $item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '<label>$1</label>', $item_html);
48
49
        }
50
51
        if (in_array('divider', $classes)) {
52
53
            $item_html = preg_replace('/<a[^>]*>( .* )<\/a>/iU', '', $item_html);
54
55
        }
56
57
        $output .= $item_html;
58
    }
59
60
    /**
61
     * @param $output
62
     * @param $depth
63
     * @param array     $args
64
     */
65
    public function start_lvl(&$output, $depth = 0, $args = [])
66
    {
67
        $output .= "\n<ul class=\"submenu menu vertical\">\n";
68
    }
69
70
}
71
72
// Offcanvas menu walker
73
/**
74
 * @param $element
75
 * @param $children_elements
76
 * @param $max_depth
77
 * @param $depth
78
 * @param $args
79
 * @param $output
80
 */
81
final class Offcanvas_Walker extends Walker_Nav_Menu
82
{
83
                                                             /**
84
     * @param $element
85
     * @param $children_elements
86
     * @param $max_depth
87
     * @param $depth
88
     * @param $args
89
     * @param $output
90
     */
91 View Code Duplication
    public function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output)
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...
92
    {
93
        $element->has_children = !empty($children_elements[$element->ID]);
94
        $element->classes[]    = ($element->current || $element->current_item_ancestor) ? 'active' : '';
95
        $element->classes[]    = ($element->has_children && 1 !== $max_depth) ? 'has-submenu' : '';
96
        parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
97
    }
98
99
    /**
100
     * @param $output
101
     * @param $object
102
     * @param $depth
103
     * @param array                $args
104
     * @param $current_object_id
105
     */
106
    public function start_el(&$output, $object, $depth = 0, $args = [], $current_object_id = 0)
107
    {
108
        $item_html = '';
109
        parent::start_el($item_html, $object, $depth, $args);
110
        $classes = empty($object->classes) ? [] : (array) $object->classes;
111
112
        if (in_array('label', $classes)) {
113
114
            $item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '<label>$1</label>', $item_html);
115
116
        }
117
118
        $output .= $item_html;
119
    }
120
121
    /**
122
     * @param $output
123
     * @param $depth
124
     * @param array     $args
125
     */
126
    public function start_lvl(&$output, $depth = 0, $args = [])
127
    {
128
        $output .= "\n<ul class=\"left-submenu\">\n<li class=\"back\"><a href=\"#\">" . __('Back', 'podium') . "</a></li>\n";
129
    }
130
131
}
132