Conditions | 28 |
Paths | > 20000 |
Total Lines | 87 |
Code Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
62 | public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
||
63 | $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; |
||
64 | |||
65 | /** |
||
66 | * Dividers, Headers or Disabled |
||
67 | * ============================= |
||
68 | * Determine whether the item is a Divider, Header, Disabled or regular |
||
69 | * menu item. To prevent errors we use the strcasecmp() function to so a |
||
70 | * comparison that is not case sensitive. The strcasecmp() function returns |
||
71 | * a 0 if the strings are equal. |
||
72 | */ |
||
73 | if ( 0 === strcasecmp( $item->attr_title, 'divider' ) && 1 === $depth ) { |
||
74 | $output .= $indent . '<li role="presentation" class="divider">'; |
||
75 | } elseif ( 0 === strcasecmp( $item->title, 'divider' ) && 1 === $depth ) { |
||
76 | $output .= $indent . '<li role="presentation" class="divider">'; |
||
77 | } elseif ( 0 === strcasecmp( $item->attr_title, 'dropdown-header' ) && 1 === $depth ) { |
||
78 | $output .= $indent . '<li role="presentation" class="dropdown-header">' . esc_attr( $item->title ); |
||
79 | } elseif ( 0 === strcasecmp( $item->attr_title, 'disabled' ) ) { |
||
80 | $output .= $indent . '<li role="presentation" class="disabled"><a href="#">' . esc_attr( $item->title ) . '</a>'; |
||
81 | } else { |
||
82 | $value = ''; |
||
83 | $class_names = $value; |
||
84 | $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
||
85 | $classes[] = 'menu-item-' . $item->ID; |
||
86 | $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); |
||
87 | if ( $args->has_children ) { |
||
88 | $class_names .= ' dropdown'; |
||
89 | } |
||
90 | if ( in_array( 'current-menu-item', $classes, true ) ) { |
||
91 | $class_names .= ' active'; |
||
92 | } |
||
93 | $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
||
94 | $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args ); |
||
95 | $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
||
96 | $output .= $indent . '<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' . $id . $value . $class_names . '>'; |
||
97 | $atts = array(); |
||
98 | |||
99 | if ( empty( $item->attr_title ) ) { |
||
100 | $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; |
||
101 | } else { |
||
102 | $atts['title'] = $item->attr_title; |
||
103 | } |
||
104 | |||
105 | $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
||
106 | $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
||
107 | // If item has_children add atts to a. |
||
108 | if ( $args->has_children && 0 === $depth ) { |
||
109 | $atts['href'] = '#'; |
||
110 | $atts['data-toggle'] = 'dropdown'; |
||
111 | $atts['class'] = 'dropdown-toggle'; |
||
112 | $atts['aria-haspopup'] = 'true'; |
||
113 | } else { |
||
114 | $atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
||
115 | } |
||
116 | $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); |
||
117 | $attributes = ''; |
||
118 | foreach ( $atts as $attr => $value ) { |
||
119 | if ( ! empty( $value ) ) { |
||
120 | $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
||
121 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
||
122 | } |
||
123 | } |
||
124 | $item_output = $args->before; |
||
125 | |||
126 | /* |
||
127 | * Glyphicons/Font-Awesome |
||
128 | * =========== |
||
129 | * Since the the menu item is NOT a Divider or Header we check the see |
||
130 | * if there is a value in the attr_title property. If the attr_title |
||
131 | * property is NOT null we apply it as the class name for the glyphicon. |
||
132 | */ |
||
133 | if ( ! empty( $item->attr_title ) ) { |
||
134 | $pos = strpos( esc_attr( $item->attr_title ), 'glyphicon' ); |
||
135 | if ( false !== $pos ) { |
||
136 | $item_output .= '<a' . $attributes . '><span class="glyphicon ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></span> '; |
||
137 | } else { |
||
138 | $item_output .= '<a' . $attributes . '><i class="fa ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></i> '; |
||
139 | } |
||
140 | } else { |
||
141 | $item_output .= '<a' . $attributes . '>'; |
||
142 | } |
||
143 | $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; |
||
144 | $item_output .= ( $args->has_children && 0 === $depth ) ? ' <span class="caret"></span></a>' : '</a>'; |
||
145 | $item_output .= $args->after; |
||
146 | $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
||
147 | } // End if(). |
||
148 | } |
||
149 | |||
224 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.