| Conditions | 27 |
| Paths | > 20000 |
| Total Lines | 167 |
| Code Lines | 114 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 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 |
||
| 19 | public function search_form( $atts = array() ) { |
||
| 20 | $classes = 'search-form lsx-search-form form-inline'; |
||
| 21 | |||
| 22 | if ( isset( $atts['class'] ) ) { |
||
| 23 | $classes .= $atts['class']; |
||
| 24 | } |
||
| 25 | |||
| 26 | $placeholder = __( 'Where do you want to go?', 'lsx-search' ); |
||
| 27 | |||
| 28 | if ( isset( $atts['placeholder'] ) ) { |
||
| 29 | $placeholder = $atts['placeholder']; |
||
| 30 | } |
||
| 31 | |||
| 32 | $action = '/'; |
||
| 33 | |||
| 34 | if ( isset( $atts['action'] ) ) { |
||
| 35 | $action = $atts['action']; |
||
| 36 | } |
||
| 37 | |||
| 38 | $method = 'get'; |
||
| 39 | |||
| 40 | if ( isset( $atts['method'] ) ) { |
||
| 41 | $method = $atts['method']; |
||
| 42 | } |
||
| 43 | |||
| 44 | $button_label = __( 'Search', 'lsx-search' ); |
||
| 45 | |||
| 46 | if ( isset( $atts['button_label'] ) ) { |
||
| 47 | $button_label = $atts['button_label']; |
||
| 48 | } |
||
| 49 | |||
| 50 | $button_class = 'btn cta-btn '; |
||
| 51 | |||
| 52 | if ( isset( $atts['button_class'] ) ) { |
||
| 53 | $button_class .= $atts['button_class']; |
||
| 54 | } |
||
| 55 | |||
| 56 | $engine = false; |
||
| 57 | |||
| 58 | if ( isset( $atts['engine'] ) ) { |
||
| 59 | $engine = $atts['engine']; |
||
| 60 | } |
||
| 61 | |||
| 62 | $engine_select = false; |
||
| 63 | |||
| 64 | if ( isset( $atts['engine_select'] ) ) { |
||
| 65 | $engine_select = true; |
||
| 66 | } |
||
| 67 | |||
| 68 | $display_search_field = true; |
||
| 69 | |||
| 70 | if ( isset( $atts['search_field'] ) ) { |
||
| 71 | $display_search_field = (boolean) $atts['search_field']; |
||
| 72 | } |
||
| 73 | |||
| 74 | $facets = false; |
||
| 75 | |||
| 76 | if ( isset( $atts['facets'] ) ) { |
||
| 77 | $facets = $atts['facets']; |
||
| 78 | } |
||
| 79 | |||
| 80 | $combo_box = false; |
||
| 81 | |||
| 82 | if ( isset( $atts['combo_box'] ) ) { |
||
| 83 | $combo_box = true; |
||
| 84 | } |
||
| 85 | |||
| 86 | $return = ''; |
||
| 87 | |||
| 88 | ob_start(); ?> |
||
| 89 | |||
| 90 | <?php do_action( 'lsx_search_form_before' ); ?> |
||
| 91 | |||
| 92 | <nav class="navbar navbar-light bg-light"> |
||
| 93 | |||
| 94 | <form class="<?php echo esc_attr( $classes ); ?>" action="<?php echo esc_attr( $action ); ?>" method="<?php echo esc_attr( $method ); ?>"> |
||
| 95 | |||
| 96 | <?php do_action( 'lsx_search_form_top' ); ?> |
||
| 97 | |||
| 98 | <div class="input-group navbar-nav"> |
||
| 99 | <?php if ( true === $display_search_field ) : ?> |
||
| 100 | <div class="field"> |
||
| 101 | <input class="search-field form-control" name="s" type="search" placeholder="<?php echo esc_attr( $placeholder ); ?>" autocomplete="off"> |
||
| 102 | </div> |
||
| 103 | <?php endif; ?> |
||
| 104 | |||
| 105 | <?php if ( false !== $engine_select && false !== $engine && 'default' !== $engine ) : |
||
| 106 | $engines = explode( '|',$engine ); ?> |
||
| 107 | <div class="field engine-select"> |
||
| 108 | <div class="dropdown nav-item"> |
||
| 109 | <?php |
||
| 110 | $plural = 's'; |
||
| 111 | if ( 'accommodation' === $engine[0] ) { |
||
| 112 | $plural = ''; |
||
| 113 | } |
||
| 114 | ?> |
||
| 115 | <button id="engine" data-selection="<?php echo esc_attr( $engines[0] ); ?>" class="btn border-btn btn-dropdown dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo esc_html( ucwords( str_replace( '_', ' ',$engines[0] ) ) . $plural ); ?> <span class="caret"></span></button> |
||
| 116 | <ul class="dropdown-menu"> |
||
| 117 | <?php |
||
| 118 | foreach ( $engines as $engine ) { |
||
| 119 | $plural = 's'; |
||
| 120 | if ( 'accommodation' === $engine ) { |
||
| 121 | $plural = ''; |
||
| 122 | } |
||
| 123 | echo '<li><a data-value="' . esc_attr( $engine ) . '" href="#">' . esc_html( ucfirst( str_replace( '_', ' ',$engine ) ) . $plural ) . '</a></li>'; |
||
| 124 | } |
||
| 125 | ?> |
||
| 126 | </ul> |
||
| 127 | </div> |
||
| 128 | </div> |
||
| 129 | <?php endif; ?> |
||
| 130 | |||
| 131 | <?php if ( false !== $facets ) { |
||
| 132 | $facets = explode( '|',$facets ); |
||
| 133 | |||
| 134 | if ( ! is_array( $facets ) ) { |
||
| 135 | $facets = array( $facets ); |
||
| 136 | } |
||
| 137 | |||
| 138 | $field_class = 'field'; |
||
| 139 | |||
| 140 | if ( false !== $combo_box ) { |
||
| 141 | $this->combo_box( $facets ); |
||
| 142 | $field_class .= ' combination-toggle hidden'; |
||
| 143 | } |
||
| 144 | |||
| 145 | foreach ( $facets as $facet ) { |
||
| 146 | ?> |
||
| 147 | <div class="<?php echo wp_kses_post( $field_class ); ?>"> |
||
| 148 | <?php |
||
| 149 | $facet = FWP()->helper->get_facet_by_name( $facet ); |
||
| 150 | if ( isset( $facet['source'] ) ) { |
||
| 151 | $values = $this->get_form_facet( $facet['source'] ); |
||
| 152 | } else { |
||
| 153 | $values = array(); |
||
| 154 | } |
||
| 155 | $facet_display_type = apply_filters( 'lsx_search_form_field_type', 'select', $facet ); |
||
| 156 | $this->display_form_field( $facet_display_type,$facet,$values,$combo_box ); |
||
| 157 | ?> |
||
| 158 | </div> |
||
| 159 | <?php |
||
| 160 | } |
||
| 161 | } ?> |
||
| 162 | |||
| 163 | <div class="field submit-button"> |
||
| 164 | <button class="<?php echo esc_attr( $button_class ); ?>" type="submit"><?php echo wp_kses_post( $button_label ); ?></button> |
||
| 165 | </div> |
||
| 166 | |||
| 167 | <?php if ( false === $engine_select && false !== $engine && 'default' !== $engine ) : ?> |
||
| 168 | <input name="engine" type="hidden" value="<?php echo esc_attr( $engine ); ?>"> |
||
| 169 | <?php endif; ?> |
||
| 170 | </div> |
||
| 171 | |||
| 172 | <?php do_action( 'lsx_search_form_bottom' ); ?> |
||
| 173 | |||
| 174 | </form> |
||
| 175 | |||
| 176 | </nav> |
||
| 177 | |||
| 178 | <?php do_action( 'lsx_search_form_after' ); ?> |
||
| 179 | <?php |
||
| 180 | $return = ob_get_clean(); |
||
| 181 | |||
| 182 | $return = preg_replace( '/[\n]+/', ' ', $return ); |
||
| 183 | $return = preg_replace( '/[\t]+/', ' ', $return ); |
||
| 184 | |||
| 185 | return $return; |
||
| 186 | } |
||
| 304 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.