NHSLeadership / nightingale-wp

Other
1 stars 0 forks source link

Refactor nested IFs in walker-menu.php #50

Closed Android63 closed 6 years ago

Android63 commented 7 years ago

Maybe use switch instead

Android63 commented 6 years ago

The only if statement with several options is:

        if( in_array('subnav-header', $classes) ) {
          // if css classes include text 'subnav-header' then display sub-menu panel header
          $item_output .= '<h4 class="u-margin-bottom-small">' . $item->title . '</h4>';
        } else if( in_array('subnav-description', $classes) ) {
          // if css classes include text 'subnav-description' then display sub-menu panel description
          $item_output .= '<p class="u-margin-bottom-small"><small>' . $item->title . '</small></p>';
        } else if( in_array('subnav-button', $classes) ) {
          // if css classes include text 'subnav-button' then display sub-menu panel button
          $item_output .= '<p class="u-margin-bottom-small"><a href="' . $url . '" class="c-btn  c-btn--primary  c-btn--full">'. $item->title .'</a></p>';
        } else {
          // standard menu item
          $item_output .= '<li class = "c-nav-primary__item"><a href="' . $url . '" class = "c-nav-primary__link" >' . $item->title . '</a></li><!-- .c-nav-primary__item -->';
        }

and, since each option is chosen based on the presence of a particular string in an array, it's not a simple switch with a variable holding one of several possible values.

Therefore I propose closing this issue. What do you reckon @cehwitham?