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 |
||
| 4 | class Lsx_Bootstrap_Navwalker extends Walker_Nav_Menu { |
||
| 5 | |||
| 6 | /** |
||
| 7 | * @see Walker::start_lvl() |
||
| 8 | * @since 3.0.0 |
||
| 9 | * |
||
| 10 | * @param string $output Passed by reference. Used to append additional content. |
||
| 11 | * @param int $depth Depth of page. Used for padding. |
||
| 12 | */ |
||
| 13 | public function start_lvl( &$output, $depth = 0, $args = array() ) { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param string $item Passed by reference. Used to append additional content. |
||
| 20 | */ |
||
| 21 | public function filter_default_pages( &$item ) { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @see Walker::start_el() |
||
| 28 | * @since 3.0.0 |
||
| 29 | * |
||
| 30 | * @param string $output Passed by reference. Used to append additional content. |
||
| 31 | * @param object $item Menu item data object. |
||
| 32 | * @param int $depth Depth of menu item. Used for padding. |
||
| 33 | * @param int $current_page Menu item ID. |
||
|
|
|||
| 34 | * @param object $args |
||
| 35 | */ |
||
| 36 | public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Traverse elements to create list from elements. |
||
| 143 | * |
||
| 144 | * Display one element if the element doesn't have any children otherwise, |
||
| 145 | * display the element and its children. Will only traverse up to the max |
||
| 146 | * depth and no ignore elements under that depth. |
||
| 147 | * |
||
| 148 | * This method shouldn't be called directly, use the walk() method instead. |
||
| 149 | * |
||
| 150 | * @see Walker::start_el() |
||
| 151 | * @since 2.5.0 |
||
| 152 | * |
||
| 153 | * @param object $element Data object |
||
| 154 | * @param array $children_elements List of elements to continue traversing. |
||
| 155 | * @param int $max_depth Max depth to traverse. |
||
| 156 | * @param int $depth Depth of current element. |
||
| 157 | * @param array $args |
||
| 158 | * @param string $output Passed by reference. Used to append additional content. |
||
| 159 | * @return null Null on failure with no changes to parameters. |
||
| 160 | */ |
||
| 161 | public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Menu Fallback |
||
| 176 | * ============= |
||
| 177 | * If this function is assigned to the wp_nav_menu's fallback_cb variable |
||
| 178 | * and a manu has not been assigned to the theme location in the WordPress |
||
| 179 | * menu manager the function with display nothing to a non-logged in user, |
||
| 180 | * and will add a link to the WordPress menu manager if logged in as an admin. |
||
| 181 | * |
||
| 182 | * @param array $args passed from the wp_nav_menu function. |
||
| 183 | * |
||
| 184 | */ |
||
| 185 | public static function fallback( $args ) { |
||
| 222 | } |
||
| 223 | |||
| 234 |
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.