| Conditions | 27 |
| Paths | > 20000 |
| Total Lines | 90 |
| 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 |
||
| 58 | public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
||
| 59 | $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * If this is a default menu being called we need to fix |
||
| 63 | * the item object thats coming through. |
||
| 64 | */ |
||
| 65 | if ( ! isset( $item->title ) ) { |
||
| 66 | return; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Dividers, Headers or Disabled |
||
| 71 | * ============================= |
||
| 72 | * Determine whether the item is a Divider, Header, Disabled or regular |
||
| 73 | * menu item. To prevent errors we use the strcasecmp() function to so a |
||
| 74 | * comparison that is not case sensitive. The strcasecmp() function returns |
||
| 75 | * a 0 if the strings are equal. |
||
| 76 | */ |
||
| 77 | if ( 0 == strcasecmp( $item->attr_title, 'divider' ) && 1 === $depth ) { |
||
| 78 | $output .= $indent . '<li role="presentation" class="divider">'; |
||
| 79 | } elseif ( 0 == strcasecmp( $item->title, 'divider' ) && 1 === $depth ) { |
||
| 80 | $output .= $indent . '<li role="presentation" class="divider">'; |
||
| 81 | } elseif ( 0 == strcasecmp( $item->attr_title, 'dropdown-header' ) && 1 === $depth ) { |
||
| 82 | $output .= $indent . '<li role="presentation" class="dropdown-header">' . esc_attr( $item->title ); |
||
| 83 | } elseif ( 0 == strcasecmp( $item->attr_title, 'disabled' ) ) { |
||
| 84 | $output .= $indent . '<li role="presentation" class="disabled"><a href="#">' . esc_attr( $item->title ) . '</a>'; |
||
| 85 | } else { |
||
| 86 | $class_names = ''; |
||
| 87 | $value = ''; |
||
| 88 | |||
| 89 | $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
||
| 90 | $classes[] = 'menu-item-' . $item->ID; |
||
| 91 | |||
| 92 | $classes = apply_filters( 'lsx_nav_menu_css_class', array_filter( $classes ), $item, $args , $depth ); |
||
| 93 | |||
| 94 | $class_names = join( ' ', $classes ); |
||
| 95 | |||
| 96 | if ( $args->has_children ) |
||
| 97 | $class_names .= ' dropdown'; |
||
| 98 | |||
| 99 | if ( in_array( 'current-menu-item', $classes ) ) |
||
| 100 | $class_names .= ' active'; |
||
| 101 | |||
| 102 | if ( in_array( 'current-menu-parent', $classes ) ) |
||
| 103 | $class_names .= ' active'; |
||
| 104 | |||
| 105 | //Check if this is ment to be a "social" type menu |
||
| 106 | $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
||
| 107 | |||
| 108 | $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args ); |
||
| 109 | $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
||
| 110 | |||
| 111 | $output .= $indent . '<li' . $id . $value . $class_names . '>'; |
||
| 112 | |||
| 113 | $atts = array(); |
||
| 114 | $atts['title'] = ! empty( $item->title ) ? $item->title : ''; |
||
| 115 | $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
||
| 116 | $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
||
| 117 | |||
| 118 | // If item has_children add atts to a. |
||
| 119 | if ( $args->has_children ) { |
||
| 120 | $atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
||
| 121 | $atts['data-toggle'] = 'dropdown'; |
||
| 122 | $atts['class'] = 'dropdown-toggle'; |
||
| 123 | $atts['aria-haspopup'] = 'true'; |
||
| 124 | } else { |
||
| 125 | $atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
||
| 126 | } |
||
| 127 | |||
| 128 | $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); |
||
| 129 | |||
| 130 | $attributes = ''; |
||
| 131 | foreach ( $atts as $attr => $value ) { |
||
| 132 | if ( ! empty( $value ) ) { |
||
| 133 | $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
||
| 134 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | $item_output = $args->before; |
||
| 139 | |||
| 140 | $item_output .= '<a' . $attributes . '>'; |
||
| 141 | $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; |
||
| 142 | $item_output .= ( $args->has_children && 0 === $depth ) ? ' <span class="caret"></span></a>' : '</a>'; |
||
| 143 | $item_output .= $args->after; |
||
| 144 | |||
| 145 | $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 237 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.