| Conditions | 4 |
| Paths | 4 |
| Total Lines | 60 |
| 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 |
||
| 76 | public function getMenu($walker_object, $canvas = 'onCanvass') |
||
| 77 | { |
||
| 78 | if (has_nav_menu('main-nav')) { |
||
| 79 | // check if menu exists |
||
| 80 | if ('onCanvass' == $canvas) { |
||
| 81 | // check if the menu is off-canvas |
||
| 82 | $onCanvas = [ |
||
| 83 | 'theme_location' => 'main-nav', |
||
| 84 | 'menu' => '', |
||
| 85 | 'container' => false, |
||
| 86 | 'items_wrap' => '<ul id="%1$s" class="%2$s show-for-medium" data-dropdown-menu>%3$s</ul>', |
||
| 87 | 'container_class' => '', |
||
| 88 | 'container_id' => '', |
||
| 89 | 'menu_class' => 'dropdown menu', |
||
| 90 | 'menu_id' => '', |
||
| 91 | 'echo' => true, |
||
| 92 | 'fallback_cb' => 'wp_nav_menu', |
||
| 93 | 'before' => '', |
||
| 94 | 'after' => '', |
||
| 95 | 'link_before' => '', |
||
| 96 | 'link_after' => '', |
||
| 97 | 'depth' => 0, |
||
| 98 | 'walker' => $walker_object |
||
| 99 | ]; |
||
| 100 | |||
| 101 | wp_nav_menu($onCanvas); |
||
| 102 | |||
| 103 | } elseif ('offCanvas' == $canvas) { |
||
| 104 | $offCanvas = [ |
||
| 105 | 'theme_location' => 'main-nav', |
||
| 106 | 'menu' => '', |
||
| 107 | 'container' => '', |
||
| 108 | 'container_class' => '', |
||
| 109 | 'container_id' => '', |
||
| 110 | 'menu_class' => 'button-group', |
||
| 111 | 'menu_id' => '', |
||
| 112 | 'echo' => true, |
||
| 113 | 'fallback_cb' => 'wp_nav_menu', |
||
| 114 | 'before' => '', |
||
| 115 | 'after' => '', |
||
| 116 | 'link_before' => '', |
||
| 117 | 'link_after' => '', |
||
| 118 | 'items_wrap' => '<ul class="off-canvas-list %2$s" role="navigation">%3$s</ul>', |
||
| 119 | 'depth' => 0, |
||
| 120 | 'walker' => $walker_object |
||
| 121 | ]; |
||
| 122 | |||
| 123 | wp_nav_menu($offCanvas); |
||
| 124 | |||
| 125 | } else { |
||
| 126 | // if no type - wrong parameter error |
||
| 127 | echo "<div class='alert label'>error invalid canvas value use: onCanvass or offCanvas (default: 'onCanvass')</div>"; |
||
| 128 | } |
||
| 129 | |||
| 130 | } else { |
||
| 131 | // no menu |
||
| 132 | echo "<div class='alert label'>Menus do not exist please create one</div>"; |
||
| 133 | } |
||
| 134 | |||
| 135 | } |
||
| 136 | |||
| 197 |