| Conditions | 33 |
| Paths | > 20000 |
| Total Lines | 206 |
| Lines | 7 |
| Ratio | 3.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 |
||
| 102 | public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
||
| 103 | View Code Duplication | if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
| 104 | $t = ''; |
||
| 105 | $n = ''; |
||
| 106 | } else { |
||
| 107 | $t = "\t"; |
||
| 108 | $n = "\n"; |
||
| 109 | } |
||
| 110 | $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; |
||
| 111 | |||
| 112 | $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
||
| 113 | |||
| 114 | // Initialize some holder variables to store specially handled item |
||
| 115 | // wrappers and icons. |
||
| 116 | $linkmod_classes = array(); |
||
| 117 | $icon_classes = array(); |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Get an updated $classes array without linkmod or icon classes. |
||
| 121 | * |
||
| 122 | * NOTE: linkmod and icon class arrays are passed by reference and |
||
| 123 | * are maybe modified before being used later in this function. |
||
| 124 | */ |
||
| 125 | $classes = self::seporate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth ); |
||
| 126 | |||
| 127 | // Join any icon classes plucked from $classes into a string. |
||
| 128 | $icon_class_string = join( ' ', $icon_classes ); |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Filters the arguments for a single nav menu item. |
||
| 132 | * |
||
| 133 | * WP 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 | // Add .dropdown or .active classes where they are needed. |
||
| 142 | if ( isset( $args->has_children ) && $args->has_children ) { |
||
| 143 | $classes[] = 'dropdown'; |
||
| 144 | } |
||
| 145 | if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) { |
||
| 146 | $classes[] = 'active'; |
||
| 147 | } |
||
| 148 | |||
| 149 | // Add some additional default classes to the item. |
||
| 150 | $classes[] = 'menu-item-' . $item->ID; |
||
| 151 | $classes[] = 'nav-item'; |
||
| 152 | |||
| 153 | // Allow filtering the classes. |
||
| 154 | $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ); |
||
| 155 | |||
| 156 | // Form a string of classes in format: class="class_names". |
||
| 157 | $class_names = join( ' ', $classes ); |
||
| 158 | $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Filters the ID applied to a menu item's list item element. |
||
| 162 | * |
||
| 163 | * @param string $menu_id The ID that is applied to the menu item's `<li>` element. |
||
| 164 | * @param WP_Post $item The current menu item. |
||
| 165 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
| 166 | * @param int $depth Depth of menu item. Used for padding. |
||
| 167 | * |
||
| 168 | * @since WP 3.0.1 |
||
| 169 | * @since WP 4.1.0 The `$depth` parameter was added. |
||
| 170 | * |
||
| 171 | */ |
||
| 172 | $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
||
| 173 | $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
||
| 174 | |||
| 175 | $output .= $indent . '<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' . $id . $class_names . '>'; |
||
| 176 | |||
| 177 | // initialize array for holding the $atts for the link item. |
||
| 178 | $atts = array(); |
||
| 179 | |||
| 180 | // Set title from item to the $atts array - if title is empty then |
||
| 181 | // default to item title. |
||
| 182 | if ( empty( $item->attr_title ) ) { |
||
| 183 | $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; |
||
| 184 | } else { |
||
| 185 | $atts['title'] = $item->attr_title; |
||
| 186 | } |
||
| 187 | |||
| 188 | $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
||
| 189 | if ( '_blank' === $item->target && empty( $item->xfn ) ) { // Thanks to LukaszJaro, see https://github.com/understrap/understrap/issues/973 |
||
| 190 | $atts['rel'] = 'noopener noreferrer'; |
||
| 191 | } else { |
||
| 192 | $atts['rel'] = $item->xfn; |
||
| 193 | } |
||
| 194 | |||
| 195 | // If item has_children add atts to <a>. |
||
| 196 | if ( isset( $args->has_children ) && $args->has_children && 0 === $depth && $args->depth > 1 ) { |
||
| 197 | $atts['href'] = '#'; |
||
| 198 | $atts['data-toggle'] = 'dropdown'; |
||
| 199 | $atts['aria-haspopup'] = 'true'; |
||
| 200 | $atts['aria-expanded'] = 'false'; |
||
| 201 | $atts['class'] = 'dropdown-toggle nav-link'; |
||
| 202 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
||
| 203 | } else { |
||
| 204 | $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
||
| 205 | // Items in dropdowns use .dropdown-item instead of .nav-link. |
||
| 206 | if ( $depth > 0 ) { |
||
| 207 | $atts['class'] = 'dropdown-item'; |
||
| 208 | } else { |
||
| 209 | $atts['class'] = 'nav-link'; |
||
| 210 | } |
||
| 211 | } |
||
| 212 | |||
| 213 | // update atts of this item based on any custom linkmod classes. |
||
| 214 | $atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
||
| 215 | // Allow filtering of the $atts array before using it. |
||
| 216 | $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
||
| 217 | |||
| 218 | // Build a string of html containing all the atts for the item. |
||
| 219 | $attributes = ''; |
||
| 220 | foreach ( $atts as $attr => $value ) { |
||
| 221 | if ( ! empty( $value ) ) { |
||
| 222 | $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
||
| 223 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
||
| 224 | } |
||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Set a typeflag to easily test if this is a linkmod or not. |
||
| 229 | */ |
||
| 230 | $linkmod_type = self::get_linkmod_type( $linkmod_classes ); |
||
| 231 | |||
| 232 | /** |
||
| 233 | * START appending the internal item contents to the output. |
||
| 234 | */ |
||
| 235 | $item_output = isset( $args->before ) ? $args->before : ''; |
||
| 236 | /** |
||
| 237 | * This is the start of the internal nav item. Depending on what |
||
| 238 | * kind of linkmod we have we may need different wrapper elements. |
||
| 239 | */ |
||
| 240 | if ( '' !== $linkmod_type ) { |
||
| 241 | // is linkmod, output the required element opener. |
||
| 242 | $item_output .= self::linkmod_element_open( $linkmod_type, $attributes ); |
||
| 243 | } else { |
||
| 244 | // With no link mod type set this must be a standard <a> tag. |
||
| 245 | $item_output .= '<a' . $attributes . '>'; |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Initiate empty icon var, then if we have a string containing any |
||
| 250 | * icon classes form the icon markup with an <i> element. This is |
||
| 251 | * output inside of the item before the $title (the link text). |
||
| 252 | */ |
||
| 253 | $icon_html = ''; |
||
| 254 | if ( ! empty( $icon_class_string ) ) { |
||
| 255 | // append an <i> with the icon classes to what is output before links. |
||
| 256 | $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** This filter is documented in wp-includes/post-template.php */ |
||
| 260 | $title = apply_filters( 'the_title', $item->title, $item->ID ); |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Filters a menu item's title. |
||
| 264 | * |
||
| 265 | * @param string $title The menu item's title. |
||
| 266 | * @param WP_Post $item The current menu item. |
||
| 267 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
| 268 | * @param int $depth Depth of menu item. Used for padding. |
||
| 269 | * |
||
| 270 | * @since WP 4.4.0 |
||
| 271 | * |
||
| 272 | */ |
||
| 273 | $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
||
| 274 | |||
| 275 | /** |
||
| 276 | * If the .sr-only class was set apply to the nav items text only. |
||
| 277 | */ |
||
| 278 | if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
||
| 279 | $title = self::wrap_for_screen_reader( $title ); |
||
| 280 | $keys_to_unset = array_keys( $linkmod_classes, 'sr-only' ); |
||
| 281 | foreach ( $keys_to_unset as $k ) { |
||
| 282 | unset( $linkmod_classes[ $k ] ); |
||
| 283 | } |
||
| 284 | } |
||
| 285 | |||
| 286 | // Put the item contents into $output. |
||
| 287 | $item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
||
| 288 | /** |
||
| 289 | * This is the end of the internal nav item. We need to close the |
||
| 290 | * correct element depending on the type of link or link mod. |
||
| 291 | */ |
||
| 292 | if ( '' !== $linkmod_type ) { |
||
| 293 | // is linkmod, output the required element opener. |
||
| 294 | $item_output .= self::linkmod_element_close( $linkmod_type, $attributes ); |
||
| 295 | } else { |
||
| 296 | // With no link mod type set this must be a standard <a> tag. |
||
| 297 | $item_output .= '</a>'; |
||
| 298 | } |
||
| 299 | |||
| 300 | $item_output .= isset( $args->after ) ? $args->after : ''; |
||
| 301 | |||
| 302 | /** |
||
| 303 | * END appending the internal item contents to the output. |
||
| 304 | */ |
||
| 305 | $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
||
| 306 | |||
| 307 | } |
||
| 308 | |||
| 582 |
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.