1 | <?php |
||
2 | namespace lsx\search\classes\admin; |
||
3 | |||
4 | use CMB_Tab_Field; |
||
0 ignored issues
–
show
|
|||
5 | |||
6 | /** |
||
7 | * Houses the functions for the CMB2 Settings page. |
||
8 | * |
||
9 | * @package lsx-search |
||
10 | */ |
||
11 | class Settings_Theme { |
||
0 ignored issues
–
show
Class name "Settings_Theme" 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 ![]() |
|||
12 | |||
13 | /** |
||
14 | * Holds class instance |
||
15 | * |
||
16 | * @since 1.0.0 |
||
17 | * |
||
18 | * @var object \lsx\search\classes\admin\Settings_Theme() |
||
19 | */ |
||
20 | protected static $instance = null; |
||
21 | |||
22 | /** |
||
23 | * Will return true if this is the LSX Search settings page. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | public $is_options_page = false; |
||
28 | |||
29 | /** |
||
30 | * Holds the id and labels for the navigation. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | public $navigation = array(); |
||
35 | |||
36 | /** |
||
37 | * Contructor |
||
38 | */ |
||
39 | public function __construct() { |
||
0 ignored issues
–
show
|
|||
40 | add_filter( 'cmb2_enqueue_css', array( $this, 'disable_cmb2_styles' ), 1, 1 ); |
||
41 | add_action( 'cmb2_before_form', array( $this, 'generate_navigation' ), 10, 4 ); |
||
42 | add_action( 'cmb2_before_title_field_row', array( $this, 'output_tab_open_div' ), 10, 1 ); |
||
43 | add_action( 'cmb2_after_tab_closing_field_row', array( $this, 'output_tab_closing_div' ), 10, 1 ); |
||
44 | add_action( 'cmb2_render_tab_closing', array( $this, 'cmb2_render_callback_for_tab_closing' ), 10, 5 ); |
||
45 | add_filter( 'cmb2_sanitize_tab_closing', array( $this, 'cmb2_sanitize_tab_closing_callback' ), 10, 2 ); |
||
46 | add_action( 'cmb2_after_form', array( $this, 'navigation_js' ), 10, 4 ); |
||
47 | add_filter( 'cmb2_options_page_redirect_url', array( $this, 'add_tab_argument' ), 10, 1 ); |
||
48 | } |
||
0 ignored issues
–
show
|
|||
49 | |||
50 | /** |
||
51 | * Return an instance of this class. |
||
52 | * |
||
53 | * @since 1.0.0 |
||
54 | * |
||
55 | * @return object \lsx\search\classes\admin\Settings_Theme() A single instance of this class. |
||
56 | */ |
||
57 | public static function get_instance() { |
||
0 ignored issues
–
show
|
|||
58 | // If the single instance hasn't been set, set it now. |
||
59 | if ( null == self::$instance ) { |
||
0 ignored issues
–
show
|
|||
60 | self::$instance = new self(); |
||
61 | } |
||
62 | return self::$instance; |
||
63 | } |
||
0 ignored issues
–
show
|
|||
64 | |||
65 | /** |
||
66 | * Disable CMB2 styles on front end forms. |
||
67 | * |
||
68 | * @return bool $enabled Whether to enable (enqueue) styles. |
||
69 | */ |
||
70 | public function disable_cmb2_styles( $enabled ) { |
||
0 ignored issues
–
show
|
|||
71 | if ( is_admin() ) { |
||
0 ignored issues
–
show
|
|||
72 | $current_screen = get_current_screen(); |
||
73 | if ( is_object( $current_screen ) && 'settings_page_lsx-search-settings' === $current_screen->id ) { |
||
0 ignored issues
–
show
|
|||
74 | $enabled = false; |
||
75 | } |
||
76 | } |
||
77 | return $enabled; |
||
78 | } |
||
0 ignored issues
–
show
|
|||
79 | |||
80 | /** |
||
81 | * Generates the tabbed navigation for the settings page. |
||
82 | * |
||
83 | * @param string $cmb_id |
||
84 | * @param string $object_id |
||
85 | * @param string $object_type |
||
86 | * @param object $cmb2_obj |
||
87 | * @return void |
||
88 | */ |
||
89 | public function generate_navigation( $cmb_id, $object_id, $object_type, $cmb2_obj ) { |
||
0 ignored issues
–
show
|
|||
90 | if ( 'lsx_search_settings' === $cmb_id && 'lsx-search-settings' === $object_id && 'options-page' === $object_type ) { |
||
0 ignored issues
–
show
|
|||
91 | $this->navigation = array(); |
||
92 | $this->is_options_page = true; |
||
0 ignored issues
–
show
It seems like
true of type true is incompatible with the declared type array of property $is_options_page .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||
93 | if ( isset( $cmb2_obj->meta_box['fields'] ) && ! empty( $cmb2_obj->meta_box['fields'] ) ) { |
||
0 ignored issues
–
show
|
|||
94 | foreach ( $cmb2_obj->meta_box['fields'] as $field_index => $field ) { |
||
0 ignored issues
–
show
|
|||
95 | if ( 'title' === $field['type'] ) { |
||
0 ignored issues
–
show
|
|||
96 | $this->navigation[ $field_index ] = $field['name']; |
||
97 | } |
||
98 | } |
||
99 | } |
||
100 | $this->output_navigation(); |
||
101 | } |
||
102 | } |
||
0 ignored issues
–
show
|
|||
103 | |||
104 | /** |
||
105 | * Outputs the WP style navigation for the Settings page. |
||
106 | * |
||
107 | * @return void |
||
108 | */ |
||
109 | public function output_navigation() { |
||
0 ignored issues
–
show
|
|||
110 | if ( ! empty( $this->navigation ) ) { |
||
0 ignored issues
–
show
|
|||
111 | ?> |
||
112 | <div class="wp-filter hide-if-no-js"> |
||
113 | <ul class="filter-links"> |
||
114 | <?php |
||
115 | $first_tab = true; |
||
116 | $total = count( $this->navigation ); |
||
117 | $count = 0; |
||
118 | $separator = ' |'; |
||
119 | $selected_tab = ''; |
||
120 | if ( isset( $_GET['cmb_tab'] ) && '' !== $_GET['cmb_tab'] ) { |
||
0 ignored issues
–
show
|
|||
121 | $selected_tab = sanitize_text_field( $_GET['cmb_tab'] ); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 1 space but found 2 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. ![]() |
|||
122 | $selected_tab = 'settings_' . $selected_tab; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 1 space but found 2 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. ![]() |
|||
123 | } |
||
124 | foreach ( $this->navigation as $key => $label ) { |
||
0 ignored issues
–
show
|
|||
125 | $count++; |
||
126 | $current_css = ''; |
||
127 | if ( ( true === $first_tab && '' === $selected_tab ) || $key === $selected_tab ) { |
||
0 ignored issues
–
show
|
|||
128 | $first_tab = false; |
||
129 | $current_css = 'current'; |
||
130 | } |
||
131 | if ( $count === $total ) { |
||
0 ignored issues
–
show
|
|||
132 | $separator = ''; |
||
133 | } |
||
134 | ?> |
||
135 | <li><a href="#" class="<?php echo esc_attr( $current_css ); ?>" data-sort="<?php echo esc_attr( $key ); ?>_tab"><?php echo esc_attr( $label ); ?></a><?php echo esc_attr( $separator ); ?></li> |
||
136 | <?php |
||
137 | } |
||
138 | ?> |
||
139 | </ul> |
||
140 | </div> |
||
141 | <?php |
||
142 | } |
||
143 | } |
||
0 ignored issues
–
show
|
|||
144 | |||
145 | /** |
||
146 | * Outputs the opening tab div. |
||
147 | * |
||
148 | * @param object $field CMB2_Field(); |
||
149 | * @return void |
||
150 | */ |
||
151 | public function output_tab_open_div( $field ) { |
||
0 ignored issues
–
show
|
|||
152 | if ( true === $this->is_options_page && isset( $field->args['type'] ) && 'title' === $field->args['type'] ) { |
||
0 ignored issues
–
show
|
|||
153 | ?> |
||
154 | <div id="<?php echo esc_attr( $field->args['id'] ); ?>_tab" class="tab tab-nav hidden"> |
||
155 | <?php |
||
156 | } |
||
157 | } |
||
0 ignored issues
–
show
|
|||
158 | |||
159 | /** |
||
160 | * Outputs the opening closing div. |
||
161 | * |
||
162 | * @param object $field CMB2_Field(); |
||
163 | * @return void |
||
164 | */ |
||
165 | public function output_tab_closing_div( $field ) { |
||
0 ignored issues
–
show
|
|||
166 | if ( true === $this->is_options_page && isset( $field->args['type'] ) && 'tab_closing' === $field->args['type'] ) { |
||
0 ignored issues
–
show
|
|||
167 | ?> |
||
168 | </div> |
||
169 | <?php |
||
170 | } |
||
171 | } |
||
0 ignored issues
–
show
|
|||
172 | |||
173 | public function cmb2_render_callback_for_tab_closing( $field, $escaped_value, $object_id, $object_type, $field_type_object ) { |
||
0 ignored issues
–
show
|
|||
174 | return; |
||
0 ignored issues
–
show
|
|||
175 | } |
||
0 ignored issues
–
show
|
|||
176 | |||
177 | public function cmb2_sanitize_tab_closing_callback( $override_value, $value ) { |
||
0 ignored issues
–
show
|
|||
178 | return ''; |
||
179 | } |
||
0 ignored issues
–
show
|
|||
180 | |||
181 | /** |
||
182 | * Outputs the Script for the tabbed navigation. |
||
183 | * |
||
184 | * @param string $cmb_id |
||
185 | * @param string $object_id |
||
186 | * @param string $object_type |
||
187 | * @param object $cmb2_obj |
||
188 | * @return void |
||
189 | */ |
||
190 | public function navigation_js( $cmb_id, $object_id, $object_type, $cmb2_obj ) { |
||
0 ignored issues
–
show
|
|||
191 | if ( 'lsx_search_settings' === $cmb_id && 'lsx-search-settings' === $object_id && 'options-page' === $object_type ) { |
||
0 ignored issues
–
show
|
|||
192 | ?> |
||
193 | <script> |
||
194 | var LSX_SEARCH_CMB2 = Object.create( null ); |
||
195 | |||
196 | ;( function( $, window, document, undefined ) { |
||
197 | |||
198 | 'use strict'; |
||
199 | |||
200 | LSX_SEARCH_CMB2.document = $(document); |
||
201 | |||
202 | /** |
||
203 | * Start the JS Class |
||
204 | */ |
||
205 | LSX_SEARCH_CMB2.init = function() { |
||
206 | var tab = LSX_SEARCH_CMB2.urlParam( 'cmb_tab' ); |
||
207 | if ( 0 === tab || '0' === tab ) { |
||
208 | tab = ''; |
||
209 | } |
||
210 | LSX_SEARCH_CMB2.addTabInput( tab ); |
||
211 | LSX_SEARCH_CMB2.prepNavigation( tab ); |
||
212 | LSX_SEARCH_CMB2.watchNavigation(); |
||
213 | }; |
||
214 | |||
215 | LSX_SEARCH_CMB2.addTabInput = function( tab = '' ) { |
||
216 | var counter = 1; |
||
217 | $( "form.cmb-form" ).append('<input type="hidden" name="cmb_tab" value="' + tab + '" />'); |
||
218 | } |
||
219 | |||
220 | LSX_SEARCH_CMB2.prepNavigation = function( tab = '' ) { |
||
221 | var counter = 1; |
||
222 | $( ".tab.tab-nav" ).each(function(){ |
||
223 | console.log( tab ); |
||
224 | if ( ( 1 !== counter && '' === tab ) || ( '' !== tab && 'settings_' + tab + '_tab' !== $( this ).attr('id') ) ) { |
||
225 | $( this ).hide().removeClass('hidden'); |
||
226 | } else { |
||
227 | $( this ).addClass( 'current' ).removeClass('hidden'); |
||
228 | } |
||
229 | counter++; |
||
230 | }); |
||
231 | } |
||
232 | |||
233 | LSX_SEARCH_CMB2.watchNavigation = function() { |
||
234 | $( ".wp-filter li a" ).on( 'click', function(event){ |
||
235 | event.preventDefault(); |
||
236 | // Change the current Tab heading. |
||
237 | $( ".wp-filter li a" ).removeClass('current'); |
||
238 | $( this ).addClass('current'); |
||
239 | |||
240 | // Change the current tab div. |
||
241 | var target = $( this ).attr('data-sort'); |
||
242 | $( ".tab.tab-nav.current" ).hide().removeClass('current'); |
||
243 | $( "#"+target ).show().addClass('current'); |
||
244 | $( 'input[name="cmb_tab"]').val(target); |
||
245 | }); |
||
246 | }; |
||
247 | |||
248 | LSX_SEARCH_CMB2.urlParam = function(name){ |
||
249 | var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); |
||
250 | if ( results == null ){ |
||
251 | return 0; |
||
252 | } else { |
||
253 | return results[1] || 0; |
||
254 | } |
||
255 | } |
||
256 | |||
257 | LSX_SEARCH_CMB2.document.ready( function() { |
||
258 | LSX_SEARCH_CMB2.init(); |
||
259 | } ); |
||
260 | |||
261 | } )( jQuery, window, document ); |
||
262 | </script> |
||
263 | <?php |
||
264 | } |
||
265 | } |
||
0 ignored issues
–
show
|
|||
266 | |||
267 | /** |
||
268 | * This will add the tab selection to the url. |
||
269 | * |
||
270 | * @param string $url |
||
271 | * @return void |
||
272 | */ |
||
273 | public function add_tab_argument( $url ) { |
||
0 ignored issues
–
show
|
|||
274 | if ( isset( $_POST['cmb_tab'] ) && '' !== $_POST['cmb_tab'] ) { // @codingStandardsIgnoreLine |
||
275 | $tab_selection = sanitize_text_field( $_POST['cmb_tab'] ); // @codingStandardsIgnoreLine |
||
276 | $tab_selection = str_replace( array( 'settings_', '_tab' ), '', $tab_selection ); // @codingStandardsIgnoreLine |
||
277 | if ( 'single' !== $tab_selection ) { |
||
0 ignored issues
–
show
|
|||
278 | $url = add_query_arg( 'cmb_tab', $tab_selection, $url ); |
||
279 | } else { |
||
280 | $url = remove_query_arg( 'cmb_tab', $url ); |
||
281 | } |
||
282 | } |
||
283 | return $url; |
||
284 | } |
||
0 ignored issues
–
show
|
|||
285 | } |
||
286 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths