| Conditions | 14 |
| Paths | 2048 |
| Total Lines | 125 |
| Code Lines | 35 |
| Lines | 13 |
| Ratio | 10.4 % |
| 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 |
||
| 117 | public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
||
| 118 | View Code Duplication | if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
| 119 | $t = ''; |
||
| 120 | $n = ''; |
||
| 121 | } else { |
||
| 122 | $t = "\t"; |
||
| 123 | $n = "\n"; |
||
| 124 | } |
||
| 125 | $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; |
||
| 126 | |||
| 127 | $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
||
| 128 | $classes[] = 'menu-item-' . $item->ID; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Filters the arguments for a single nav menu item. |
||
| 132 | * |
||
| 133 | * @since 4.4.0 |
||
| 134 | * |
||
| 135 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
| 136 | * @param WP_Post $item Menu item data object. |
||
| 137 | * @param int $depth Depth of menu item. Used for padding. |
||
| 138 | */ |
||
| 139 | $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Filters the CSS class(es) applied to a menu item's list item element. |
||
| 143 | * |
||
| 144 | * @since 3.0.0 |
||
| 145 | * @since 4.1.0 The `$depth` parameter was added. |
||
| 146 | * |
||
| 147 | * @param array $classes The CSS classes that are applied to the menu item's `<li>` element. |
||
| 148 | * @param WP_Post $item The current menu item. |
||
| 149 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
| 150 | * @param int $depth Depth of menu item. Used for padding. |
||
| 151 | */ |
||
| 152 | $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) ); |
||
| 153 | $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Filters the ID applied to a menu item's list item element. |
||
| 157 | * |
||
| 158 | * @since 3.0.1 |
||
| 159 | * @since 4.1.0 The `$depth` parameter was added. |
||
| 160 | * |
||
| 161 | * @param string $menu_id The ID that is applied to the menu item's `<li>` element. |
||
| 162 | * @param WP_Post $item The current menu item. |
||
| 163 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
| 164 | * @param int $depth Depth of menu item. Used for padding. |
||
| 165 | */ |
||
| 166 | $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth ); |
||
| 167 | $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
||
| 168 | |||
| 169 | $output .= $indent . '<li' . $id . $class_names .'>'; |
||
| 170 | |||
| 171 | $atts = array(); |
||
| 172 | $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : ''; |
||
| 173 | $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
||
| 174 | $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
||
| 175 | $atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Filters the HTML attributes applied to a menu item's anchor element. |
||
| 179 | * |
||
| 180 | * @since 3.6.0 |
||
| 181 | * @since 4.1.0 The `$depth` parameter was added. |
||
| 182 | * |
||
| 183 | * @param array $atts { |
||
| 184 | * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored. |
||
| 185 | * |
||
| 186 | * @type string $title Title attribute. |
||
| 187 | * @type string $target Target attribute. |
||
| 188 | * @type string $rel The rel attribute. |
||
| 189 | * @type string $href The href attribute. |
||
| 190 | * } |
||
| 191 | * @param WP_Post $item The current menu item. |
||
| 192 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
| 193 | * @param int $depth Depth of menu item. Used for padding. |
||
| 194 | */ |
||
| 195 | $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
||
| 196 | |||
| 197 | $attributes = ''; |
||
| 198 | View Code Duplication | foreach ( $atts as $attr => $value ) { |
|
| 199 | if ( ! empty( $value ) ) { |
||
| 200 | $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
||
| 201 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | |||
| 205 | /** This filter is documented in wp-includes/post-template.php */ |
||
| 206 | $title = apply_filters( 'the_title', $item->title, $item->ID ); |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Filters a menu item's title. |
||
| 210 | * |
||
| 211 | * @since 4.4.0 |
||
| 212 | * |
||
| 213 | * @param string $title The menu item's title. |
||
| 214 | * @param WP_Post $item The current menu item. |
||
| 215 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
| 216 | * @param int $depth Depth of menu item. Used for padding. |
||
| 217 | */ |
||
| 218 | $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
||
| 219 | |||
| 220 | $item_output = $args->before; |
||
| 221 | $item_output .= '<a'. $attributes .'>'; |
||
| 222 | $item_output .= $args->link_before . $title . $args->link_after; |
||
| 223 | $item_output .= '</a>'; |
||
| 224 | $item_output .= $args->after; |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Filters a menu item's starting output. |
||
| 228 | * |
||
| 229 | * The menu item's starting output only includes `$args->before`, the opening `<a>`, |
||
| 230 | * the menu item's title, the closing `</a>`, and `$args->after`. Currently, there is |
||
| 231 | * no filter for modifying the opening and closing `<li>` for a menu item. |
||
| 232 | * |
||
| 233 | * @since 3.0.0 |
||
| 234 | * |
||
| 235 | * @param string $item_output The menu item's starting HTML output. |
||
| 236 | * @param WP_Post $item Menu item data object. |
||
| 237 | * @param int $depth Depth of menu item. Used for padding. |
||
| 238 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
| 239 | */ |
||
| 240 | $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
||
| 241 | } |
||
| 242 | |||
| 267 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type
arrayand suggests a stricter type likearray<String>.Most often this is a case of a parameter that can be null in addition to its declared types.