1 | <?php |
||||
2 | /** |
||||
3 | * LSX_Search_FacetWP_Hierarchy Frontend Main Class |
||||
4 | */ |
||||
5 | |||||
6 | namespace lsx\search\classes\facetwp; |
||||
7 | |||||
8 | class Hierarchy { |
||||
9 | |||||
10 | /** |
||||
11 | * Holds class instance |
||||
12 | * |
||||
13 | * @since 1.0.0 |
||||
14 | * |
||||
15 | * @var object \lsx\search\classes\facetwp\Hierarchy() |
||||
16 | */ |
||||
17 | protected static $instance = null; |
||||
18 | |||||
19 | /** |
||||
20 | * Constructor |
||||
21 | */ |
||||
22 | public function __construct() { |
||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
23 | add_filter( 'facetwp_facet_html', array( $this, 'checkbox_facet_html' ), 100, 2 ); |
||||
24 | } |
||||
0 ignored issues
–
show
|
|||||
25 | |||||
26 | /** |
||||
27 | * Return an instance of this class. |
||||
28 | * |
||||
29 | * @since 1.0.0 |
||||
30 | * |
||||
31 | * @return object \lsx\search\classes\facetwp\Hierarchy() A single instance of this class. |
||||
32 | */ |
||||
33 | public static function get_instance() { |
||||
0 ignored issues
–
show
|
|||||
34 | // If the single instance hasn't been set, set it now. |
||||
35 | if ( null === self::$instance ) { |
||||
0 ignored issues
–
show
|
|||||
36 | self::$instance = new self(); |
||||
37 | } |
||||
38 | return self::$instance; |
||||
39 | } |
||||
0 ignored issues
–
show
|
|||||
40 | |||||
41 | public function checkbox_facet_html( $output, $params ) { |
||||
0 ignored issues
–
show
|
|||||
42 | if ( 'checkboxes' === $params['facet']['type'] && 'yes' === $params['facet']['hierarchical'] ) { |
||||
0 ignored issues
–
show
|
|||||
43 | $output = $this->render_hierarchy( $params ); |
||||
44 | } |
||||
45 | return $output; |
||||
46 | } |
||||
0 ignored issues
–
show
|
|||||
47 | |||||
48 | /** |
||||
49 | * Generate the facet HTML (hierarchical taxonomies) |
||||
50 | */ |
||||
51 | function render_hierarchy( $params ) { |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
render_hierarchy .
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with ![]() |
|||||
52 | |||||
53 | $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. ![]() |
|||||
54 | $facet = $params['facet']; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 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. ![]() |
|||||
55 | $selected_values = (array) $params['selected_values']; |
||||
56 | $values = FWP()->helper->sort_taxonomy_values( $params['values'], $facet['orderby'] ); |
||||
0 ignored issues
–
show
The function
FWP was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() 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. ![]() |
|||||
57 | |||||
58 | $init_depth = -1; |
||||
59 | $last_depth = -1; |
||||
60 | |||||
61 | foreach ( $values as $result ) { |
||||
0 ignored issues
–
show
|
|||||
62 | $depth = (int) $result['depth']; |
||||
63 | |||||
64 | /*if ( -1 == $last_depth ) { |
||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
48% 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. ![]() |
|||||
65 | $init_depth = $depth; |
||||
66 | } |
||||
67 | elseif ( $depth > $last_depth ) { |
||||
68 | $output .= '<div class="facetwp-depth">'; |
||||
69 | } |
||||
70 | elseif ( $depth < $last_depth ) { |
||||
71 | for ( $i = $last_depth; $i > $depth; $i-- ) { |
||||
72 | $output .= '</div>'; |
||||
73 | } |
||||
74 | }*/ |
||||
75 | |||||
76 | $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. ![]() |
|||||
77 | $selected .= ( 0 == $result['counter'] && '' == $selected ) ? ' disabled' : ''; |
||||
0 ignored issues
–
show
|
|||||
78 | |||||
79 | $is_child = ( 0 == $result['parent_id'] && '0' == $result['parent_id'] ) ? ' is-child' : ''; |
||||
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. ![]() |
|||||
80 | $depth_css = ' depth-' . $result['depth']; |
||||
81 | |||||
82 | $output .= '<div class="facetwp-checkbox' . $selected . $is_child . $depth_css . '" data-parent-id="' . esc_attr( $result['parent_id'] ) . '" data-value="' . esc_attr( $result['facet_value'] ) . '">'; |
||||
83 | $output .= esc_html( $result['facet_display_value'] ) . ' <span class="facetwp-counter">(' . $result['counter'] . ')</span>'; |
||||
84 | $output .= '</div>'; |
||||
85 | |||||
86 | $last_depth = $depth; |
||||
87 | } |
||||
88 | |||||
89 | for ( $i = $last_depth; $i > $init_depth; $i-- ) { |
||||
0 ignored issues
–
show
|
|||||
90 | $output .= '</div>'; |
||||
91 | } |
||||
92 | |||||
93 | return $output; |
||||
94 | } |
||||
0 ignored issues
–
show
|
|||||
95 | } |
||||
96 |