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