Skip to content

Commit 6c5fdf1

Browse files
Merge pull request #394 from contactashish13/issue-393
new PHPCS rules for strict comparison
2 parents 3df57c4 + 4c38c5e commit 6c5fdf1

File tree

19 files changed

+76
-69
lines changed

19 files changed

+76
-69
lines changed

classes/Visualizer/Gutenberg/Block.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Visualizer_Gutenberg_Block {
4646
* Returns an instance of this class.
4747
*/
4848
public static function get_instance() {
49-
if ( null == self::$instance ) {
49+
if ( null === self::$instance ) {
5050
self::$instance = new Visualizer_Gutenberg_Block();
5151
}
5252
return self::$instance;
@@ -297,19 +297,19 @@ public function format_chart_data( $data, $series ) {
297297
continue;
298298
}
299299

300-
if ( $row['type'] == 'number' ) {
300+
if ( $row['type'] === 'number' ) {
301301
foreach ( $data as $o => $col ) {
302302
$data[ $o ][ $i ] = ( is_numeric( $col[ $i ] ) ) ? floatval( $col[ $i ] ) : ( is_numeric( str_replace( ',', '', $col[ $i ] ) ) ? floatval( str_replace( ',', '', $col[ $i ] ) ) : null );
303303
}
304304
}
305305

306-
if ( $row['type'] == 'boolean' ) {
306+
if ( $row['type'] === 'boolean' ) {
307307
foreach ( $data as $o => $col ) {
308308
$data[ $o ][ $i ] = ! empty( $col[ $i ] ) ? filter_validate( $col[ $i ], FILTER_VALIDATE_BOOLEAN ) : null;
309309
}
310310
}
311311

312-
if ( $row['type'] == 'timeofday' ) {
312+
if ( $row['type'] === 'timeofday' ) {
313313
foreach ( $data as $o => $col ) {
314314
$date = new DateTime( '1984-03-16T' . $col[ $i ] );
315315
if ( $date ) {
@@ -323,7 +323,7 @@ public function format_chart_data( $data, $series ) {
323323
}
324324
}
325325

326-
if ( $row['type'] == 'string' ) {
326+
if ( $row['type'] === 'string' ) {
327327
foreach ( $data as $o => $col ) {
328328
$data[ $o ][ $i ] = $this->toUTF8( $col[ $i ] );
329329
}

classes/Visualizer/Module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function _getDataAs( $chart_id, $type ) {
159159
$success = false;
160160
if ( $chart_id ) {
161161
$chart = get_post( $chart_id );
162-
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
162+
$success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
163163
}
164164
if ( $success ) {
165165
$settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );

classes/Visualizer/Module/Admin.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public function restoreRevision( $post_id, $revision_id ) {
133133
* @access public
134134
*/
135135
public function init() {
136+
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
136137
if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' == get_user_option( 'rich_editing' ) ) {
137138
$this->_addFilter( 'mce_external_languages', 'add_tinymce_lang', 10, 1 );
138139
$this->_addFilter( 'mce_external_plugins', 'tinymce_plugin', 10, 1 );
@@ -465,7 +466,7 @@ private static function handleDeprecatedCharts( $types, $enabledOnly, $get2Darra
465466
*/
466467
public function renderTemplates() {
467468
global $pagenow;
468-
if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) {
469+
if ( 'post.php' !== $pagenow && 'post-new.php' !== $pagenow ) {
469470
return;
470471
}
471472
$render = new Visualizer_Render_Templates();
@@ -485,7 +486,7 @@ public function renderTemplates() {
485486
* @param string $suffix The current page suffix.
486487
*/
487488
public function enqueueLibraryScripts( $suffix ) {
488-
if ( $suffix == $this->_libraryPage ) {
489+
if ( $suffix === $this->_libraryPage ) {
489490
wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION );
490491
$this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
491492
wp_enqueue_media();
@@ -579,7 +580,7 @@ private function getQuery() {
579580
);
580581
// add chart type filter to the query arguments
581582
$filter = filter_input( INPUT_GET, 'type' );
582-
if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
583+
if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes(), true ) ) {
583584
$query_args['meta_query'] = array(
584585
array(
585586
'key' => Visualizer_Plugin::CF_CHART_TYPE,
@@ -631,7 +632,7 @@ public function renderLibraryPage() {
631632
);
632633
// add chart type filter to the query arguments
633634
$filter = filter_input( INPUT_GET, 'type' );
634-
if ( ! ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) ) {
635+
if ( ! ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes(), true ) ) ) {
635636
$filter = 'all';
636637
}
637638

@@ -738,7 +739,7 @@ public function renderLibraryPage() {
738739
* @return array Updated array of action links.
739740
*/
740741
public function getPluginActionLinks( $links, $file ) {
741-
if ( $file == plugin_basename( VISUALIZER_BASEFILE ) ) {
742+
if ( $file === plugin_basename( VISUALIZER_BASEFILE ) ) {
742743
array_unshift(
743744
$links,
744745
sprintf(
@@ -765,7 +766,7 @@ public function getPluginActionLinks( $links, $file ) {
765766
* @return array Updated array of plugin meta links.
766767
*/
767768
public function getPluginMetaLinks( $plugin_meta, $plugin_file ) {
768-
if ( $plugin_file == plugin_basename( VISUALIZER_BASEFILE ) ) {
769+
if ( $plugin_file === plugin_basename( VISUALIZER_BASEFILE ) ) {
769770
// knowledge base link
770771
$plugin_meta[] = sprintf(
771772
'<a href="https://github.com/codeinwp/visualizer/wiki" target="_blank">%s</a>',

classes/Visualizer/Module/Chart.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getCharts() {
9595
$filter = filter_input( INPUT_GET, 'filter', FILTER_SANITIZE_STRING );
9696
}
9797

98-
if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
98+
if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes(), true ) ) {
9999
$query_args['meta_query'] = array(
100100
array(
101101
'key' => Visualizer_Plugin::CF_CHART_TYPE,
@@ -202,7 +202,7 @@ public static function _sendResponse( $results ) {
202202
* @access public
203203
*/
204204
public function deleteChart() {
205-
$is_post = $_SERVER['REQUEST_METHOD'] == 'POST';
205+
$is_post = $_SERVER['REQUEST_METHOD'] === 'POST';
206206
$input_method = $is_post ? INPUT_POST : INPUT_GET;
207207
$chart_id = $success = false;
208208
$nonce = wp_verify_nonce( filter_input( $input_method, 'nonce' ) );
@@ -220,7 +220,7 @@ public function deleteChart() {
220220
);
221221
if ( $chart_id ) {
222222
$chart = get_post( $chart_id );
223-
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
223+
$success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
224224
}
225225
}
226226
if ( $success ) {
@@ -277,7 +277,7 @@ public function renderChartPages() {
277277
defined( 'IFRAME_REQUEST' ) || define( 'IFRAME_REQUEST', 1 );
278278
// check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
279279
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
280-
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
280+
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
281281
$this->deleteOldCharts();
282282
$default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
283283
$source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
@@ -436,8 +436,8 @@ private function _handleDataAndSettingsPage() {
436436
if ( isset( $_POST['map_api_key'] ) ) {
437437
update_option( 'visualizer-map-api-key', $_POST['map_api_key'] );
438438
}
439-
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) {
440-
if ( $this->_chart->post_status == 'auto-draft' ) {
439+
if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) {
440+
if ( $this->_chart->post_status === 'auto-draft' ) {
441441
$this->_chart->post_status = 'publish';
442442

443443
// ensure that a revision is not created. If a revision is created it will have the proper data and the parent of the revision will have default data.
@@ -464,7 +464,7 @@ private function _handleDataAndSettingsPage() {
464464
$sidebar->__data = $data['data'];
465465
} else {
466466
$sidebar = apply_filters( 'visualizer_pro_chart_type_sidebar', '', $data );
467-
if ( $sidebar != '' ) {
467+
if ( $sidebar !== '' ) {
468468
$sidebar->__series = $data['series'];
469469
$sidebar->__data = $data['data'];
470470
}
@@ -517,10 +517,10 @@ private function _handleDataAndSettingsPage() {
517517
$render->custom_css = $data['css'];
518518
$render->sidebar = $sidebar;
519519
if ( filter_input( INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN ) ) {
520-
$render->button = filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART
520+
$render->button = filter_input( INPUT_GET, 'action' ) === Visualizer_Plugin::ACTION_EDIT_CHART
521521
? esc_html__( 'Save Chart', 'visualizer' )
522522
: esc_html__( 'Create Chart', 'visualizer' );
523-
if ( filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART ) {
523+
if ( filter_input( INPUT_GET, 'action' ) === Visualizer_Plugin::ACTION_EDIT_CHART ) {
524524
$render->cancel_button = esc_html__( 'Cancel', 'visualizer' );
525525
}
526526
} else {
@@ -543,9 +543,9 @@ private function _handleDataAndSettingsPage() {
543543
*/
544544
private function _handleTypesPage() {
545545
// process post request
546-
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ) ) ) {
546+
if ( $_SERVER['REQUEST_METHOD'] === 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ) ) ) {
547547
$type = filter_input( INPUT_POST, 'type' );
548-
if ( in_array( $type, Visualizer_Plugin::getChartTypes() ) ) {
548+
if ( in_array( $type, Visualizer_Plugin::getChartTypes(), true ) ) {
549549
// save new chart type
550550
update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, $type );
551551
// if the chart has default data, update it with appropriate default data for new type
@@ -608,7 +608,7 @@ public function uploadData() {
608608
// check chart, if chart exists
609609
// do not use filter_input as it does not work for phpunit test cases, use filter_var instead
610610
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
611-
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
611+
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
612612
if ( ! $can_die ) {
613613
return;
614614
}
@@ -638,6 +638,7 @@ public function uploadData() {
638638
if ( isset( $_POST['vz-import-time'] ) ) {
639639
apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] );
640640
}
641+
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
641642
} elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
642643
$source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
643644
} elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) {
@@ -703,7 +704,7 @@ public function cloneChart() {
703704
);
704705
if ( $chart_id ) {
705706
$chart = get_post( $chart_id );
706-
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
707+
$success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
707708
}
708709
}
709710
$redirect = wp_get_referer();

classes/Visualizer/Module/Frontend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function renderChart( $atts ) {
190190
);
191191

192192
// if empty id or chart does not exists, then return empty string
193-
if ( ! $atts['id'] || ! ( $chart = get_post( $atts['id'] ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
193+
if ( ! $atts['id'] || ! ( $chart = get_post( $atts['id'] ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
194194
return '';
195195
}
196196

classes/Visualizer/Module/Setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function onActivation( $plugin ) {
154154
return;
155155
}
156156

157-
if ( $plugin == VISUALIZER_BASENAME ) {
157+
if ( $plugin === VISUALIZER_BASENAME ) {
158158
wp_redirect( admin_url( 'upload.php?page=' . Visualizer_Plugin::NAME ) );
159159
exit();
160160
}

classes/Visualizer/Module/Sources.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ public function addProUpsell( $old, $feature = null ) {
133133
$biz_features = array( 'schedule-chart', 'chart-permissions', 'db-query' );
134134
$return = '';
135135
$feature = strval( $feature );
136-
if ( empty( $feature ) || ( in_array( $feature, $biz_features ) && ! apply_filters( 'visualizer_is_business', false ) ) ) {
136+
if ( empty( $feature ) || ( in_array( $feature, $biz_features, true ) && ! apply_filters( 'visualizer_is_business', false ) ) ) {
137137
$plan = 'PRO';
138-
if ( in_array( $feature, $biz_features ) ) {
138+
if ( in_array( $feature, $biz_features, true ) ) {
139139
$plan = 'DEVELOPER';
140140
}
141141
$return = '<div class="only-pro-content">';

classes/Visualizer/Render/Library.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private function _renderLibrary() {
9999
$link = "<a class=' visualizer-pro-only' href='" . Visualizer_Plugin::PRO_TEASER_URL . "' target='_blank'>";
100100
}
101101
echo '<li class="visualizer-list-item all">';
102-
if ( $type == $this->type ) {
102+
if ( $type === $this->type ) {
103103
echo '<a class=" current" href="', esc_url( add_query_arg( 'vpage', false ) ), '">';
104104
echo $label;
105105
echo '</a>';

classes/Visualizer/Render/Page/Data.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class="visualizer-select">
161161
)
162162
);
163163
foreach ( $schedules as $num => $name ) {
164+
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
164165
$extra = $num == $hours ? 'selected' : '';
165166
?>
166167
<option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
@@ -252,6 +253,7 @@ class="dashicons dashicons-lock"></span></h2>
252253
)
253254
);
254255
foreach ( $schedules as $num => $name ) {
256+
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
255257
$extra = $num == $hours ? 'selected' : '';
256258
?>
257259
<option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
@@ -283,29 +285,30 @@ class="dashicons dashicons-lock"></span></h2>
283285
class="dashicons dashicons-lock"></span></h2>
284286
<div class="viz-group-content edit-data-content">
285287
<div>
286-
<p class="viz-group-description"><?php _e( 'You can import data from the database here.', 'visualizer' ); ?></p>
287-
<form id="vz-db-wizard" action="<?php echo $save_query; ?>" method="post" target="thehole">
288-
<p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from the database.', 'visualizer' ); ?></p>
289-
<select name="refresh" id="vz-db-import-time" class="visualizer-select">
290-
<?php
291-
$bttn_label = 'visualizer_source_query' === $source_of_chart ? __( 'Modify Query', 'visualizer' ) : __( 'Create Query', 'visualizer' );
292-
$hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_DB_SCHEDULE, true );
293-
$schedules = apply_filters(
294-
'visualizer_schedules', array(
295-
'0' => __( 'Live', 'visualizer' ),
296-
'1' => __( 'Each hour', 'visualizer' ),
297-
'12' => __( 'Each 12 hours', 'visualizer' ),
298-
'24' => __( 'Each day', 'visualizer' ),
299-
'72' => __( 'Each 3 days', 'visualizer' ),
300-
)
301-
);
302-
foreach ( $schedules as $num => $name ) {
303-
$extra = $num == $hours ? 'selected' : '';
304-
?>
288+
<p class="viz-group-description"><?php _e( 'You can import data from the database here.', 'visualizer' ); ?></p>
289+
<form id="vz-db-wizard" action="<?php echo $save_query; ?>" method="post" target="thehole">
290+
<p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from the database.', 'visualizer' ); ?></p>
291+
<select name="refresh" id="vz-db-import-time" class="visualizer-select">
292+
<?php
293+
$bttn_label = 'visualizer_source_query' === $source_of_chart ? __( 'Modify Query', 'visualizer' ) : __( 'Create Query', 'visualizer' );
294+
$hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_DB_SCHEDULE, true );
295+
$schedules = apply_filters(
296+
'visualizer_schedules', array(
297+
'0' => __( 'Live', 'visualizer' ),
298+
'1' => __( 'Each hour', 'visualizer' ),
299+
'12' => __( 'Each 12 hours', 'visualizer' ),
300+
'24' => __( 'Each day', 'visualizer' ),
301+
'72' => __( 'Each 3 days', 'visualizer' ),
302+
)
303+
);
304+
foreach ( $schedules as $num => $name ) {
305+
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
306+
$extra = $num == $hours ? 'selected' : '';
307+
?>
305308
<option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
306309
<?php
307-
}
308-
?>
310+
}
311+
?>
309312
</select>
310313
<input type="hidden" name="params" id="viz-db-wizard-params">
311314

classes/Visualizer/Render/Page/Types.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function _renderContent() {
5959
echo "<a class='pro-upsell' href='" . Visualizer_Plugin::PRO_TEASER_URL . "' target='_blank'>";
6060
echo "<span class='visualizder-pro-label'>" . __( 'PREMIUM', 'visualizer' ) . '</span>';
6161
}
62-
echo '<label class="type-label', $type == $this->type ? ' type-label-selected' : '', '">';
62+
echo '<label class="type-label', $type === $this->type ? ' type-label-selected' : '', '">';
6363
echo '<span>' . $array['name'] . '</span>';
6464
if ( $array['enabled'] ) {
6565
echo '<input type="radio" class="type-radio" name="type" value="', $type, '"', checked( $type, $this->type, false ), '>';

0 commit comments

Comments
 (0)