Complex classes like LSX_Bootstrap_Navwalker often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use LSX_Bootstrap_Navwalker, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class LSX_Bootstrap_Navwalker extends Walker_Nav_Menu { |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @see Walker::start_lvl() |
||
| 31 | * @since 3.0.0 |
||
| 32 | * |
||
| 33 | * @param string $output Passed by reference. Used to append additional content. |
||
| 34 | * @param int $depth Depth of page. Used for padding. |
||
| 35 | */ |
||
| 36 | public function start_lvl( &$output, $depth = 0, $args = array() ) { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param string $item Passed by reference. Used to append additional content. |
||
| 43 | */ |
||
| 44 | public function filter_default_pages( &$item ) { |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @see Walker::start_el() |
||
| 50 | * @since 3.0.0 |
||
| 51 | * |
||
| 52 | * @param string $output Passed by reference. Used to append additional content. |
||
| 53 | * @param object $item Menu item data object. |
||
| 54 | * @param int $depth Depth of menu item. Used for padding. |
||
| 55 | * @param int $current_page Menu item ID. |
||
|
|
|||
| 56 | * @param object $args |
||
| 57 | */ |
||
| 58 | public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Traverse elements to create list from elements. |
||
| 151 | * |
||
| 152 | * Display one element if the element doesn't have any children otherwise, |
||
| 153 | * display the element and its children. Will only traverse up to the max |
||
| 154 | * depth and no ignore elements under that depth. |
||
| 155 | * |
||
| 156 | * This method shouldn't be called directly, use the walk() method instead. |
||
| 157 | * |
||
| 158 | * @see Walker::start_el() |
||
| 159 | * @since 2.5.0 |
||
| 160 | * |
||
| 161 | * @param object $element Data object |
||
| 162 | * @param array $children_elements List of elements to continue traversing. |
||
| 163 | * @param int $max_depth Max depth to traverse. |
||
| 164 | * @param int $depth Depth of current element. |
||
| 165 | * @param array $args |
||
| 166 | * @param string $output Passed by reference. Used to append additional content. |
||
| 167 | * @return null Null on failure with no changes to parameters. |
||
| 168 | */ |
||
| 169 | public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Menu Fallback |
||
| 185 | * ============= |
||
| 186 | * If this function is assigned to the wp_nav_menu's fallback_cb variable |
||
| 187 | * and a manu has not been assigned to the theme location in the WordPress |
||
| 188 | * menu manager the function with display nothing to a non-logged in user, |
||
| 189 | * and will add a link to the WordPress menu manager if logged in as an admin. |
||
| 190 | * |
||
| 191 | * @param array $args passed from the wp_nav_menu function. |
||
| 192 | * |
||
| 193 | */ |
||
| 194 | public static function fallback( $args ) { |
||
| 233 | |||
| 234 | } |
||
| 235 | |||
| 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.