1 | <?php |
||||
2 | /** |
||||
3 | * LSX Search FacetWP filters and actions |
||||
4 | * |
||||
5 | * @package lsx-search |
||||
6 | */ |
||||
7 | class LSX_Search_FacetWP { |
||||
0 ignored issues
–
show
Class name "LSX_Search_FacetWP" is not in PascalCase format
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 ![]() |
|||||
8 | |||||
9 | /** |
||||
10 | * @var object \lsx\search\classes\facetwp\Hierarchy() |
||||
11 | */ |
||||
12 | public $hierarchy; |
||||
13 | |||||
14 | /** |
||||
15 | * @var object \lsx\search\classes\facetwp\Post_Connections() |
||||
16 | */ |
||||
17 | public $post_connections; |
||||
18 | |||||
19 | /** |
||||
20 | * Class Constructor. |
||||
21 | */ |
||||
22 | public function __construct() { |
||||
0 ignored issues
–
show
|
|||||
23 | |||||
24 | require_once LSX_SEARCH_PATH . '/classes/facetwp/class-hierarchy.php'; |
||||
25 | $this->hierarchy = lsx\search\classes\facetwp\Hierarchy::get_instance(); |
||||
26 | |||||
27 | require_once LSX_SEARCH_PATH . '/classes/facetwp/class-post-connections.php'; |
||||
28 | $this->post_connections = lsx\search\classes\facetwp\Post_Connections::get_instance(); |
||||
29 | |||||
30 | add_filter( 'facetwp_pager_html', array( $this, 'facetwp_pager_html' ), 10, 2 ); |
||||
31 | add_filter( 'facetwp_result_count', array( $this, 'facetwp_result_count' ), 10, 2 ); |
||||
32 | add_filter( 'facetwp_facet_html', array( $this, 'facetwp_slide_html' ), 10, 2 ); |
||||
33 | add_filter( 'facetwp_load_css', array( $this, 'facetwp_load_css' ), 10, 1 ); |
||||
34 | add_filter( 'facetwp_index_row', array( $this, 'index_row' ), 10, 2 ); |
||||
35 | } |
||||
0 ignored issues
–
show
|
|||||
36 | |||||
37 | /** |
||||
38 | * Change FaceWP pagination HTML to be equal LSX pagination. |
||||
39 | */ |
||||
40 | public function facetwp_pager_html( $output, $params ) { |
||||
0 ignored issues
–
show
|
|||||
41 | $output = ''; |
||||
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. ![]() |
|||||
42 | $page = (int) $params['page']; |
||||
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. ![]() |
|||||
43 | $per_page = (int) $params['per_page']; |
||||
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. ![]() |
|||||
44 | $total_pages = (int) $params['total_pages']; |
||||
45 | |||||
46 | if ( 1 < $total_pages ) { |
||||
0 ignored issues
–
show
|
|||||
47 | $output .= '<div class="lsx-pagination-wrapper facetwp-custom">'; |
||||
48 | $output .= '<div class="lsx-pagination">'; |
||||
49 | // $output .= '<span class="pages">Page '. $page .' of '. $total_pages .'</span>'; |
||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
45% 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. ![]() |
|||||
50 | |||||
51 | if ( 1 < $page ) { |
||||
0 ignored issues
–
show
|
|||||
52 | $output .= '<a class="prev page-numbers facetwp-page" rel="prev" data-page="' . ( $page - 1 ) . '">«</a>'; |
||||
53 | } |
||||
54 | |||||
55 | $temp = false; |
||||
56 | |||||
57 | for ( $i = 1; $i <= $total_pages; $i++ ) { |
||||
0 ignored issues
–
show
|
|||||
58 | if ( $i == $page ) { |
||||
0 ignored issues
–
show
|
|||||
59 | $output .= '<span class="page-numbers current">' . $i . '</span>'; |
||||
60 | } elseif ( ( $page - 2 ) < $i && ( $page + 2 ) > $i ) { |
||||
0 ignored issues
–
show
|
|||||
61 | $output .= '<a class="page-numbers facetwp-page" data-page="' . $i . '">' . $i . '</a>'; |
||||
62 | } elseif ( ( $page - 2 ) >= $i && $page > 2 ) { |
||||
0 ignored issues
–
show
|
|||||
63 | if ( ! $temp ) { |
||||
0 ignored issues
–
show
|
|||||
64 | $output .= '<span class="page-numbers dots">...</span>'; |
||||
65 | $temp = true; |
||||
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. ![]() |
|||||
66 | } |
||||
67 | } elseif ( ( $page + 2 ) <= $i && ( $page + 2 ) <= $total_pages ) { |
||||
0 ignored issues
–
show
|
|||||
68 | $output .= '<span class="page-numbers dots">...</span>'; |
||||
69 | break; |
||||
70 | } |
||||
71 | } |
||||
72 | |||||
73 | if ( $page < $total_pages ) { |
||||
0 ignored issues
–
show
|
|||||
74 | $output .= '<a class="next page-numbers facetwp-page" rel="next" data-page="' . ( $page + 1 ) . '">»</a>'; |
||||
75 | } |
||||
76 | |||||
77 | $output .= '</div>'; |
||||
78 | $output .= '</div>'; |
||||
79 | } |
||||
80 | |||||
81 | return $output; |
||||
82 | } |
||||
0 ignored issues
–
show
|
|||||
83 | |||||
84 | /** |
||||
85 | * Change FaceWP result count HTML. |
||||
86 | */ |
||||
87 | public function facetwp_result_count( $output, $params ) { |
||||
0 ignored issues
–
show
|
|||||
88 | $output = $params['total']; |
||||
89 | return $output; |
||||
90 | } |
||||
0 ignored issues
–
show
|
|||||
91 | |||||
92 | /** |
||||
93 | * Change FaceWP slider HTML. |
||||
94 | */ |
||||
95 | public function facetwp_slide_html( $html, $args ) { |
||||
0 ignored issues
–
show
|
|||||
96 | if ( 'slider' === $args['facet']['type'] ) { |
||||
0 ignored issues
–
show
|
|||||
97 | $html = str_replace( 'class="facetwp-slider-reset"', 'class="btn btn-md facetwp-slider-reset"', $html ); |
||||
98 | } |
||||
99 | |||||
100 | return $html; |
||||
101 | } |
||||
0 ignored issues
–
show
|
|||||
102 | |||||
103 | /** |
||||
104 | * Change FaceWP slider HTML. |
||||
105 | */ |
||||
106 | public function facetwp_counts_html( $html, $args ) { |
||||
0 ignored issues
–
show
|
|||||
107 | if ( 'slider' === $args['facet']['type'] ) { |
||||
0 ignored issues
–
show
|
|||||
108 | $html = str_replace( 'class="facetwp-slider-reset"', 'class="btn btn-md facetwp-slider-reset"', $html ); |
||||
109 | } |
||||
110 | return $html; |
||||
111 | } |
||||
0 ignored issues
–
show
|
|||||
112 | |||||
113 | /** |
||||
114 | * Disable FacetWP styles. |
||||
115 | */ |
||||
116 | public function facetwp_load_css( $boolean ) { |
||||
0 ignored issues
–
show
|
|||||
117 | $boolean = false; |
||||
118 | return $boolean; |
||||
119 | } |
||||
0 ignored issues
–
show
|
|||||
120 | |||||
121 | /** |
||||
122 | * Get the price including the tax |
||||
123 | * @param $params |
||||
124 | * @param $class |
||||
125 | * |
||||
126 | * @return mixed |
||||
127 | */ |
||||
128 | public function index_row( $params, $class ) { |
||||
0 ignored issues
–
show
|
|||||
129 | // Custom woo fields |
||||
130 | if ( 0 === strpos( $params['facet_source'], 'woo' ) ) { |
||||
0 ignored issues
–
show
|
|||||
131 | $product = wc_get_product( $params['post_id'] ); |
||||
0 ignored issues
–
show
The function
wc_get_product 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
![]() |
|||||
132 | |||||
133 | // Price |
||||
134 | if ( in_array( $params['facet_source'], array( 'woo/price', 'woo/sale_price', 'woo/regular_price' ) ) ) { |
||||
0 ignored issues
–
show
|
|||||
135 | $price = $params['facet_value']; |
||||
136 | if ( $product->is_taxable() ) { |
||||
0 ignored issues
–
show
|
|||||
137 | $price = wc_get_price_including_tax( $product ); |
||||
0 ignored issues
–
show
The function
wc_get_price_including_tax 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
![]() |
|||||
138 | } |
||||
139 | $params['facet_value'] = $price; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 4 spaces
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. ![]() |
|||||
140 | $params['facet_display_value'] = $price; |
||||
141 | |||||
0 ignored issues
–
show
|
|||||
142 | } |
||||
143 | } |
||||
144 | return $params; |
||||
145 | } |
||||
0 ignored issues
–
show
|
|||||
146 | |||||
147 | } |
||||
148 |
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.