| Conditions | 28 |
| Paths | > 20000 |
| Total Lines | 84 |
| Code Lines | 58 |
| 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 | $class_names = $value = ''; |
||
| 83 | $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
||
| 84 | $classes[] = 'menu-item-' . $item->ID; |
||
| 85 | $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); |
||
| 86 | if ( $args->has_children ) { |
||
| 87 | $class_names .= ' dropdown'; } |
||
| 88 | if ( in_array( 'current-menu-item', $classes, true ) ) { |
||
| 89 | $class_names .= ' active'; } |
||
| 90 | $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
||
| 91 | $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args ); |
||
| 92 | $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
||
| 93 | $output .= $indent . '<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' . $id . $value . $class_names . '>'; |
||
| 94 | $atts = array(); |
||
| 95 | |||
| 96 | if ( empty( $item->attr_title ) ) { |
||
| 97 | $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; |
||
| 98 | } else { |
||
| 99 | $atts['title'] = $item->attr_title; |
||
| 100 | } |
||
| 101 | |||
| 102 | $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
||
| 103 | $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
||
| 104 | // If item has_children add atts to a. |
||
| 105 | if ( $args->has_children && 0 === $depth ) { |
||
| 106 | $atts['href'] = '#'; |
||
| 107 | $atts['data-toggle'] = 'dropdown'; |
||
| 108 | $atts['class'] = 'dropdown-toggle'; |
||
| 109 | $atts['aria-haspopup'] = 'true'; |
||
| 110 | } else { |
||
| 111 | $atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
||
| 112 | } |
||
| 113 | $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); |
||
| 114 | $attributes = ''; |
||
| 115 | foreach ( $atts as $attr => $value ) { |
||
| 116 | if ( ! empty( $value ) ) { |
||
| 117 | $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
||
| 118 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | $item_output = $args->before; |
||
| 122 | |||
| 123 | /* |
||
| 124 | * Glyphicons/Font-Awesome |
||
| 125 | * =========== |
||
| 126 | * Since the the menu item is NOT a Divider or Header we check the see |
||
| 127 | * if there is a value in the attr_title property. If the attr_title |
||
| 128 | * property is NOT null we apply it as the class name for the glyphicon. |
||
| 129 | */ |
||
| 130 | if ( ! empty( $item->attr_title ) ) : |
||
| 131 | $pos = strpos( esc_attr( $item->attr_title ), 'glyphicon' ); |
||
| 132 | if ( false !== $pos ) : |
||
| 133 | $item_output .= '<a' . $attributes . '><span class="glyphicon ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></span> '; |
||
| 134 | else : |
||
| 135 | $item_output .= '<a' . $attributes . '><i class="fa ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></i> '; |
||
| 136 | endif; |
||
| 137 | else : |
||
| 138 | $item_output .= '<a' . $attributes . '>'; |
||
| 139 | endif; |
||
| 140 | $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; |
||
| 141 | $item_output .= ( $args->has_children && 0 === $depth ) ? ' <span class="caret"></span></a>' : '</a>'; |
||
| 142 | $item_output .= $args->after; |
||
| 143 | $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 232 |
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.