1 | <?php |
||||
2 | /** |
||||
3 | * LSX_Search_FacetWP_Hierarchy Frontend Main Class |
||||
4 | */ |
||||
5 | |||||
6 | namespace lsx\search\classes\facetwp; |
||||
7 | |||||
8 | class Post_Connections { |
||||
0 ignored issues
–
show
|
|||||
9 | |||||
10 | /** |
||||
11 | * Holds class instance |
||||
12 | * |
||||
13 | * @since 1.0.0 |
||||
14 | * |
||||
15 | * @var object \lsx\search\classes\facetwp\Post_Connections() |
||||
16 | */ |
||||
17 | protected static $instance = null; |
||||
18 | |||||
19 | /** |
||||
20 | * Holds the plugin options. |
||||
21 | * |
||||
22 | * @var array |
||||
23 | */ |
||||
24 | public $options = array(); |
||||
25 | |||||
26 | /** |
||||
27 | * Constructor |
||||
28 | */ |
||||
29 | public function __construct() { |
||||
0 ignored issues
–
show
|
|||||
30 | $this->get_cmb2_options(); |
||||
31 | add_filter( 'facetwp_indexer_row_data', array( $this, 'facetwp_index_row_data' ), 10, 2 ); |
||||
32 | add_filter( 'facetwp_index_row', array( $this, 'facetwp_index_row' ), 10, 2 ); |
||||
33 | add_filter( 'facetwp_facet_html', array( $this, 'destination_facet_html' ), 10, 2 ); |
||||
34 | } |
||||
0 ignored issues
–
show
|
|||||
35 | |||||
36 | /** |
||||
37 | * Gets the cmb2 options. |
||||
38 | * |
||||
39 | * @return void |
||||
40 | */ |
||||
41 | private function get_cmb2_options() { |
||||
0 ignored issues
–
show
|
|||||
42 | $cmb2_options = get_option( 'lsx-search-settings' ); |
||||
43 | if ( false !== $cmb2_options && ! empty( $cmb2_options ) ) { |
||||
0 ignored issues
–
show
|
|||||
44 | $this->options['display'] = $cmb2_options; |
||||
45 | foreach ( $this->options['display'] as $option_key => $option_value ) { |
||||
0 ignored issues
–
show
|
|||||
46 | if ( is_array( $option_value ) && ! empty( $option_value ) ) { |
||||
0 ignored issues
–
show
|
|||||
47 | $new_values = array(); |
||||
48 | foreach ( $option_value as $empty_key => $key_value ) { |
||||
0 ignored issues
–
show
|
|||||
49 | $new_values[ $key_value ] = 'on'; |
||||
50 | } |
||||
51 | $this->options['display'][ $option_key ] = $new_values; |
||||
52 | } |
||||
53 | } |
||||
54 | } |
||||
55 | |||||
56 | /*print_r('<pre>'); |
||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
71% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||
57 | print_r($this->options); |
||||
58 | print_r('</pre>'); |
||||
59 | die();*/ |
||||
60 | } |
||||
0 ignored issues
–
show
|
|||||
61 | |||||
62 | /** |
||||
63 | * Return an instance of this class. |
||||
64 | * |
||||
65 | * @since 1.0.0 |
||||
66 | * |
||||
67 | * @return object \lsx\search\classes\facetwp\Post_Connections() A single instance of this class. |
||||
68 | */ |
||||
69 | public static function get_instance() { |
||||
0 ignored issues
–
show
|
|||||
70 | // If the single instance hasn't been set, set it now. |
||||
71 | if ( null === self::$instance ) { |
||||
0 ignored issues
–
show
|
|||||
72 | self::$instance = new self(); |
||||
73 | } |
||||
74 | return self::$instance; |
||||
75 | } |
||||
0 ignored issues
–
show
|
|||||
76 | |||||
77 | /** |
||||
78 | * Alter the rows and include extra facets rows for the continents |
||||
0 ignored issues
–
show
|
|||||
79 | */ |
||||
80 | public function facetwp_index_row_data( $rows, $params ) { |
||||
0 ignored issues
–
show
|
|||||
81 | switch ( $params['facet']['source'] ) { |
||||
0 ignored issues
–
show
|
|||||
82 | case 'cf/destination_to_tour': |
||||
83 | case 'cf/destination_to_accommodation': |
||||
84 | $countries = array(); |
||||
85 | |||||
86 | foreach ( $rows as $r_index => $row ) { |
||||
0 ignored issues
–
show
|
|||||
87 | $parent = wp_get_post_parent_id( $row['facet_value'] ); |
||||
88 | $rows[ $r_index ]['parent_id'] = $parent; |
||||
89 | |||||
90 | if ( 0 === $parent || '0' === $parent ) { |
||||
0 ignored issues
–
show
|
|||||
91 | if ( ! isset( $countries[ $r_index ] ) ) { |
||||
0 ignored issues
–
show
|
|||||
92 | $countries[ $r_index ] = $row['facet_value']; |
||||
93 | } |
||||
94 | |||||
95 | if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
96 | $rows[ $r_index ]['depth'] = 1; |
||||
97 | } else { |
||||
98 | $rows[ $r_index ]['depth'] = 0; |
||||
99 | } |
||||
100 | } else { |
||||
101 | if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
102 | $rows[ $r_index ]['depth'] = 2; |
||||
103 | } else { |
||||
104 | $rows[ $r_index ]['depth'] = 1; |
||||
105 | } |
||||
106 | } |
||||
107 | } |
||||
108 | if ( ! empty( $this->options['display']['enable_search_continent_filter'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
109 | if ( ! empty( $countries ) ) { |
||||
0 ignored issues
–
show
|
|||||
110 | foreach ( $countries as $row_index => $country ) { |
||||
0 ignored issues
–
show
|
|||||
111 | $continents = wp_get_object_terms( $country, 'continent' ); |
||||
112 | $continent_id = 0; |
||||
113 | |||||
114 | if ( ! is_wp_error( $continents ) ) { |
||||
0 ignored issues
–
show
|
|||||
115 | $new_row = $params['defaults']; |
||||
116 | if ( ! is_array( $continents ) ) { |
||||
0 ignored issues
–
show
|
|||||
117 | $continents = array( $continents ); |
||||
118 | } |
||||
119 | |||||
120 | foreach ( $continents as $continent ) { |
||||
0 ignored issues
–
show
|
|||||
121 | $new_row['facet_value'] = $continent->slug; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
122 | $new_row['facet_display_value'] = $continent->name; |
||||
123 | $continent_id = $continent->term_id; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 19 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
124 | $new_row['depth'] = 0; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
125 | } |
||||
126 | $rows[] = $new_row; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 26 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
127 | $rows[ $row_index ]['parent_id'] = $continent_id; |
||||
128 | } |
||||
129 | } |
||||
130 | } |
||||
131 | } |
||||
132 | |||||
133 | break; |
||||
134 | |||||
135 | default: |
||||
136 | break; |
||||
137 | } |
||||
138 | |||||
139 | return $rows; |
||||
140 | } |
||||
0 ignored issues
–
show
|
|||||
141 | |||||
142 | /** |
||||
143 | * Displays the destination specific settings |
||||
144 | */ |
||||
145 | public function facetwp_index_row( $params, $class ) { |
||||
0 ignored issues
–
show
|
|||||
146 | $custom_field = false; |
||||
147 | $meta_key = false; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
148 | |||||
149 | preg_match( '/cf\//', $class->facet['source'], $custom_field ); |
||||
0 ignored issues
–
show
$custom_field of type false is incompatible with the type string[] expected by parameter $matches of preg_match() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
150 | preg_match( '/_to_/', $class->facet['source'], $meta_key ); |
||||
151 | |||||
152 | if ( ! empty( $custom_field ) && ! empty( $meta_key ) ) { |
||||
0 ignored issues
–
show
|
|||||
153 | |||||
154 | if ( ( 'cf/destination_to_accommodation' === $class->facet['source'] || 'cf/destination_to_tour' === $class->facet['source'] ) && ! empty( $this->options['display']['engine_search_continent_filter'] ) && ( '0' === (string) $params['depth'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
155 | $title = ''; |
||||
156 | } else { |
||||
157 | $title = get_the_title( $params['facet_value'] ); |
||||
158 | if ( '' !== $title ) { |
||||
0 ignored issues
–
show
|
|||||
159 | $params['facet_display_value'] = $title; |
||||
160 | } |
||||
161 | if ( '' === $title && ! empty( $meta_key ) ) { |
||||
0 ignored issues
–
show
|
|||||
162 | $params['facet_value'] = ''; |
||||
163 | } |
||||
164 | } |
||||
165 | } |
||||
166 | |||||
167 | // If its a price, save the value as a standard number. |
||||
168 | if ( 'cf/price' === $class->facet['source'] ) { |
||||
0 ignored issues
–
show
|
|||||
169 | $params['facet_value'] = preg_replace( '/[^0-9.]/', '', $params['facet_value'] ); |
||||
170 | $params['facet_value'] = ltrim( $params['facet_value'], '.' ); |
||||
171 | #$params['facet_value'] = number_format( (int) $params['facet_value'], 2 ); |
||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
70% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||
172 | $params['facet_display_value'] = $params['facet_value']; |
||||
173 | } |
||||
174 | |||||
175 | // If its a duration, save the value as a standard number. |
||||
176 | if ( 'cf/duration' === $class->facet['source'] ) { |
||||
0 ignored issues
–
show
|
|||||
177 | $params['facet_value'] = preg_replace( '/[^0-9 ]/', '', $params['facet_value'] ); |
||||
178 | $params['facet_value'] = trim( $params['facet_value'] ); |
||||
179 | $params['facet_value'] = explode( ' ', $params['facet_value'] ); |
||||
180 | $params['facet_value'] = $params['facet_value'][0]; |
||||
181 | #$params['facet_value'] = (int) $params['facet_value']; |
||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
79% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||
182 | $params['facet_display_value'] = $params['facet_value']; |
||||
183 | } |
||||
184 | |||||
185 | return $params; |
||||
186 | } |
||||
0 ignored issues
–
show
|
|||||
187 | |||||
188 | /** |
||||
189 | * Checks the facet source value and outputs the destination facet HTML if needed. |
||||
190 | * |
||||
191 | * @param string $output |
||||
192 | * @param array $params |
||||
193 | * @return string |
||||
194 | */ |
||||
195 | public function destination_facet_html( $output, $params ) { |
||||
0 ignored issues
–
show
|
|||||
196 | $possible_keys = array( |
||||
197 | 'cf/destination_to_accommodation', |
||||
198 | 'cf/destination_to_tour', |
||||
199 | 'cf/destination_to_special', |
||||
200 | 'cf/destination_to_activity', |
||||
201 | 'cf/destination_to_review', |
||||
202 | 'cf/destination_to_vehicle', |
||||
203 | ); |
||||
204 | if ( in_array( $params['facet']['source'], $possible_keys ) ) { |
||||
0 ignored issues
–
show
|
|||||
205 | $output = $this->destination_facet_render( $params ); |
||||
206 | } |
||||
207 | return $output; |
||||
208 | } |
||||
0 ignored issues
–
show
|
|||||
209 | |||||
210 | /** |
||||
211 | * Generate the facet HTML |
||||
212 | */ |
||||
213 | public function destination_facet_render( $params ) { |
||||
0 ignored issues
–
show
|
|||||
214 | $facet = $params['facet']; |
||||
215 | |||||
216 | $output = ''; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
217 | $values = (array) $params['values']; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
218 | $selected_values = (array) $params['selected_values']; |
||||
219 | $soft_limit = empty( $facet['soft_limit'] ) ? 0 : (int) $facet['soft_limit']; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
220 | $countries = array(); |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
221 | $continents = array(); |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
222 | |||||
223 | $continent_terms = get_terms( |
||||
224 | array( |
||||
225 | 'taxonomy' => 'continent', |
||||
226 | ) |
||||
227 | ); |
||||
228 | |||||
229 | if ( ! is_wp_error( $continent_terms ) ) { |
||||
0 ignored issues
–
show
|
|||||
230 | foreach ( $continent_terms as $continent ) { |
||||
0 ignored issues
–
show
|
|||||
231 | $continents[ $continent->term_id ] = $continent->slug; |
||||
232 | } |
||||
233 | } |
||||
234 | |||||
235 | //Create a relationship of the facet value and the their depths |
||||
236 | $depths = array(); |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
237 | $parents = array(); |
||||
238 | foreach ( $values as $value ) { |
||||
0 ignored issues
–
show
|
|||||
239 | $depths[ $value['facet_value'] ] = (int) $value['depth']; |
||||
240 | $parents[ $value['facet_value'] ] = (int) $value['parent_id']; |
||||
241 | } |
||||
242 | |||||
243 | //Determine the current depth and check if the selected values parents are in the selected array. |
||||
244 | $current_depth = 0; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
245 | $additional_values = array(); |
||||
246 | if ( ! empty( $selected_values ) ) { |
||||
0 ignored issues
–
show
|
|||||
247 | foreach ( $selected_values as $selected ) { |
||||
0 ignored issues
–
show
|
|||||
248 | if ( $depths[ $selected ] > $current_depth ) { |
||||
0 ignored issues
–
show
|
|||||
249 | $current_depth = $depths[ $selected ]; |
||||
250 | } |
||||
251 | } |
||||
252 | $current_depth++; |
||||
253 | } |
||||
254 | |||||
255 | if ( ! empty( $additional_values ) ) { |
||||
0 ignored issues
–
show
|
|||||
256 | $selected_values = array_merge( $selected_values, $additional_values ); |
||||
257 | } |
||||
258 | |||||
259 | // This is where the items are sorted by their depth |
||||
260 | $sorted_values = array(); |
||||
261 | $stored = $values; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
262 | |||||
263 | //sort the options so |
||||
264 | foreach ( $values as $key => $result ) { |
||||
0 ignored issues
–
show
|
|||||
265 | if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
266 | if ( in_array( $result['facet_value'], $continents ) ) { |
||||
0 ignored issues
–
show
|
|||||
267 | $sorted_values[] = $result; |
||||
268 | $destinations = $this->get_countries( $stored, $result['facet_value'], $continents, '1' ); |
||||
269 | |||||
270 | if ( ! empty( $destinations ) ) { |
||||
0 ignored issues
–
show
|
|||||
271 | foreach ( $destinations as $destination ) { |
||||
0 ignored issues
–
show
|
|||||
272 | $sorted_values[] = $destination; |
||||
273 | } |
||||
274 | } |
||||
275 | } |
||||
276 | } else { |
||||
277 | if ( '0' === $result['depth'] || 0 === $result['depth'] ) { |
||||
0 ignored issues
–
show
|
|||||
278 | $sorted_values[] = $result; |
||||
279 | $destinations = $this->get_regions( $stored, $result['facet_value'], '1' ); |
||||
280 | |||||
281 | if ( ! empty( $destinations ) ) { |
||||
0 ignored issues
–
show
|
|||||
282 | foreach ( $destinations as $destination ) { |
||||
0 ignored issues
–
show
|
|||||
283 | $sorted_values[] = $destination; |
||||
284 | } |
||||
285 | } |
||||
286 | } |
||||
287 | } |
||||
288 | } |
||||
289 | $values = $sorted_values; |
||||
290 | |||||
291 | $continent_class = ''; |
||||
292 | $country_class = ''; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
293 | |||||
294 | // Run through each value and output the values. |
||||
295 | foreach ( $values as $key => $facet ) { |
||||
0 ignored issues
–
show
|
|||||
296 | $depth_type = ''; |
||||
297 | |||||
298 | if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
299 | switch ( $facet['depth'] ) { |
||||
0 ignored issues
–
show
|
|||||
300 | case '0': |
||||
301 | $depth_type = ''; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
302 | $continent_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' continent-checked' : ''; |
||||
0 ignored issues
–
show
|
|||||
303 | break; |
||||
304 | |||||
305 | case '1': |
||||
306 | $depth_type = 'country' . $continent_class; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
307 | $country_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' country-checked' : ''; |
||||
0 ignored issues
–
show
|
|||||
308 | break; |
||||
309 | |||||
310 | case '2': |
||||
311 | $depth_type = 'region' . $continent_class . $country_class; |
||||
312 | break; |
||||
313 | } |
||||
314 | } else { |
||||
315 | switch ( $facet['depth'] ) { |
||||
0 ignored issues
–
show
|
|||||
316 | case '0': |
||||
317 | $depth_type = 'country continent-checked'; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
318 | $country_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' country-checked' : ''; |
||||
0 ignored issues
–
show
|
|||||
319 | break; |
||||
320 | |||||
321 | case '1': |
||||
322 | $depth_type = 'region continent-checked' . $country_class; |
||||
323 | break; |
||||
324 | } |
||||
325 | } |
||||
326 | |||||
327 | if ( $facet['depth'] <= $current_depth ) { |
||||
0 ignored issues
–
show
|
|||||
328 | $options[] = $this->format_single_facet( $key, $facet, $selected_values, $depth_type ); |
||||
329 | } |
||||
330 | } |
||||
331 | |||||
332 | if ( ! empty( $options ) ) { |
||||
0 ignored issues
–
show
|
|||||
333 | $output = implode( '', $options ); |
||||
334 | } |
||||
335 | |||||
336 | return $output; |
||||
337 | } |
||||
0 ignored issues
–
show
|
|||||
338 | |||||
339 | /** |
||||
340 | * Gets the direct countries from the array. |
||||
341 | */ |
||||
342 | public function get_countries( $values, $parent, $continents, $depth ) { |
||||
0 ignored issues
–
show
|
|||||
343 | $children = array(); |
||||
344 | $stored = $values; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
345 | |||||
346 | foreach ( $values as $value ) { |
||||
0 ignored issues
–
show
|
|||||
347 | if ( isset( $continents[ $value['parent_id'] ] ) && $continents[ $value['parent_id'] ] === $parent && $value['depth'] === $depth ) { |
||||
0 ignored issues
–
show
|
|||||
348 | $children[] = $value; |
||||
349 | |||||
350 | $destinations = $this->get_regions( $stored, $value['facet_value'], '2' ); |
||||
351 | if ( ! empty( $destinations ) ) { |
||||
0 ignored issues
–
show
|
|||||
352 | foreach ( $destinations as $destination ) { |
||||
0 ignored issues
–
show
|
|||||
353 | $children[] = $destination; |
||||
354 | } |
||||
355 | } |
||||
356 | } |
||||
357 | } |
||||
358 | return $children; |
||||
359 | } |
||||
0 ignored issues
–
show
|
|||||
360 | |||||
361 | /** |
||||
362 | * Gets the direct regions from the array. |
||||
363 | */ |
||||
364 | public function get_regions( $values, $parent, $depth ) { |
||||
0 ignored issues
–
show
|
|||||
365 | $children = array(); |
||||
366 | foreach ( $values as $value ) { |
||||
0 ignored issues
–
show
|
|||||
367 | if ( $value['parent_id'] === $parent && $value['depth'] === $depth ) { |
||||
0 ignored issues
–
show
|
|||||
368 | $children[] = $value; |
||||
369 | } |
||||
370 | } |
||||
371 | return $children; |
||||
372 | } |
||||
0 ignored issues
–
show
|
|||||
373 | |||||
374 | public function format_single_facet( $key, $result, $selected_values, $region = '' ) { |
||||
0 ignored issues
–
show
|
|||||
375 | $temp_html = ''; |
||||
376 | |||||
377 | $selected = in_array( $result['facet_value'], $selected_values ) ? ' checked' : ''; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
378 | $selected .= ( 0 == $result['counter'] && '' == $selected ) ? ' disabled' : ''; |
||||
0 ignored issues
–
show
|
|||||
379 | $selected .= ' ' . $region; |
||||
380 | |||||
381 | $temp_html .= '<div class="facetwp-checkbox' . $selected . '" data-value="' . $result['facet_value'] . '">'; |
||||
382 | $temp_html .= $result['facet_display_value'] . ' <span class="facetwp-counter">(' . $result['counter'] . ')</span>'; |
||||
383 | $temp_html .= '</div>'; |
||||
384 | |||||
385 | return $temp_html; |
||||
386 | } |
||||
0 ignored issues
–
show
|
|||||
387 | } |
||||
388 |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider
.