| Conditions | 31 |
| Paths | > 20000 |
| Total Lines | 88 |
| Code Lines | 59 |
| 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 |
||
| 54 | public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
||
| 55 | $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; |
||
| 56 | /** |
||
| 57 | * Dividers, Headers or Disabled |
||
| 58 | * ============================= |
||
| 59 | * Determine whether the item is a Divider, Header, Disabled or regular |
||
| 60 | * menu item. To prevent errors we use the strcasecmp() function to so a |
||
| 61 | * comparison that is not case sensitive. The strcasecmp() function returns |
||
| 62 | * a 0 if the strings are equal. |
||
| 63 | */ |
||
| 64 | if ( 0 == strcasecmp( $item->attr_title, 'divider' ) && 1 === $depth ) { |
||
| 65 | $output .= $indent . '<li class="dropdown-divider" role="presentation">'; |
||
| 66 | } else if ( 0 == strcasecmp( $item->title, 'divider' ) && 1 === $depth ) { |
||
| 67 | $output .= $indent . '<li class="dropdown-divider" role="presentation">'; |
||
| 68 | } else if ( 0 == strcasecmp( $item->attr_title, 'dropdown-header' ) && 1 === $depth ) { |
||
| 69 | $output .= $indent . '<li class="dropdown-header" role="presentation">' . esc_html( $item->title ); |
||
| 70 | } else if ( 0 == strcasecmp( $item->attr_title, 'disabled' ) ) { |
||
| 71 | $output .= $indent . '<li class="disabled" role="presentation"><a href="#">' . esc_html( $item->title ) . '</a>'; |
||
| 72 | } else { |
||
| 73 | $class_names = $value = ''; |
||
| 74 | $classes = empty( $item->classes ) ? array() : ( array ) $item->classes; |
||
| 75 | $classes[] = 'nav-item menu-item-' . $item->ID; |
||
| 76 | $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); |
||
| 77 | /* |
||
| 78 | if ( $args->has_children ) |
||
| 79 | $class_names .= ' dropdown'; |
||
| 80 | */ |
||
| 81 | if ( $args->has_children && 0 === $depth ) { |
||
| 82 | $class_names .= ' dropdown'; |
||
| 83 | } elseif ( $args->has_children && $depth > 0 ) { |
||
| 84 | $class_names .= ' dropdown-submenu'; |
||
| 85 | } |
||
| 86 | if ( in_array( 'current-menu-item', $classes ) ) { |
||
| 87 | $class_names .= ' active'; |
||
| 88 | } |
||
| 89 | // remove Font Awesome icon from classes array and save the icon |
||
| 90 | // we will add the icon back in via a <span> below so it aligns with |
||
| 91 | // the menu item |
||
| 92 | if ( in_array( 'fa', $classes ) ) { |
||
| 93 | $key = array_search( 'fa', $classes ); |
||
| 94 | $icon = $classes[$key + 1]; |
||
| 95 | $class_names = str_replace( $classes[$key + 1], '', $class_names ); |
||
| 96 | $class_names = str_replace( $classes[$key], '', $class_names ); |
||
| 97 | } |
||
| 98 | |||
| 99 | $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
||
| 100 | $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args ); |
||
| 101 | $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
||
| 102 | $output .= $indent . '<li' . $id . $value . $class_names . '>'; |
||
| 103 | $atts = array(); |
||
| 104 | if ( empty( $item->attr_title ) ) { |
||
| 105 | $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; |
||
| 106 | } else { |
||
| 107 | $atts['title'] = $item->attr_title; |
||
| 108 | } |
||
| 109 | $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
||
| 110 | $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
||
| 111 | // If item has_children add atts to a. |
||
| 112 | |||
| 113 | if ( $args->has_children && 0 === $depth ) { |
||
| 114 | $atts['href'] = '#'; |
||
| 115 | $atts['data-toggle'] = 'dropdown'; |
||
| 116 | $atts['class'] = 'nav-link dropdown-toggle'; |
||
| 117 | } else { |
||
| 118 | $atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
||
| 119 | $atts['class'] = 'nav-link'; |
||
| 120 | } |
||
| 121 | $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); |
||
| 122 | $attributes = ''; |
||
| 123 | foreach ( $atts as $attr => $value ) { |
||
| 124 | if ( ! empty( $value ) ) { |
||
| 125 | $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
||
| 126 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | $item_output = $args->before; |
||
| 130 | // Font Awesome icons |
||
| 131 | if ( ! empty( $icon ) ) { |
||
| 132 | $item_output .= '<a' . $attributes . '><span class="fa ' . esc_attr( $icon ) . '"></span> '; |
||
| 133 | } else { |
||
| 134 | $item_output .= '<a' . $attributes . '>'; |
||
| 135 | } |
||
| 136 | $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; |
||
| 137 | $item_output .= ( $args->has_children && 0 === $depth ) ? ' <span class="caret"></span></a>' : '</a>'; |
||
| 138 | $item_output .= $args->after; |
||
| 139 | $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 220 |