Skip to content

Commit dc339bc

Browse files
committed
chore: fix phpcs
1 parent b0cb5db commit dc339bc

49 files changed

Lines changed: 127 additions & 187 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

classes/Visualizer/Gutenberg/Block.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ public function gutenberg_block_callback( $atts ) {
186186
return '';
187187
}
188188

189-
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
190-
if ( $atts['lazy'] == -1 || $atts['lazy'] == false ) {
189+
if ( $atts['lazy'] === '-1' || $atts['lazy'] === false ) {
191190
$atts['lazy'] = 'no';
192191
}
193192

@@ -472,11 +471,12 @@ public function get_visualizer_data( $post ) {
472471
$permissions = get_post_meta( $post_id, Visualizer_Pro::CF_PERMISSIONS, true );
473472

474473
if ( empty( $permissions ) ) {
475-
$permissions = array( 'permissions' => array(
474+
$permissions = array(
475+
'permissions' => array(
476476
'read' => 'all',
477477
'edit' => 'roles',
478478
'edit-specific' => array( 'administrator' ),
479-
),
479+
),
480480
);
481481
}
482482

@@ -824,7 +824,7 @@ public function get_permission_data( $data ) {
824824
foreach ( $users as $user ) {
825825
$options[ $i ]['value'] = $user->ID;
826826
$options[ $i ]['label'] = $user->display_name;
827-
$i++;
827+
++$i;
828828
}
829829
}
830830
break;
@@ -838,7 +838,7 @@ public function get_permission_data( $data ) {
838838
foreach ( get_editable_roles() as $name => $info ) {
839839
$options[ $i ]['value'] = $name;
840840
$options[ $i ]['label'] = $name;
841-
$i++;
841+
++$i;
842842
}
843843
}
844844
break;

classes/Visualizer/Module.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
6868
$this->_addFilter( Visualizer_Plugin::FILTER_HANDLE_REVISIONS, 'handleExistingRevisions', 10, 2 );
6969
$this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, 'getDataAs', 10, 3 );
7070
$this->_addAction( 'pre_get_posts', 'PreGetPosts' );
71-
register_shutdown_function( array($this, 'onShutdown') );
72-
71+
register_shutdown_function( array( $this, 'onShutdown' ) );
7372
}
7473

7574
/**
@@ -114,16 +113,16 @@ protected function _addAction( $tag, $method, $methodClass = null, $priority = 1
114113
* @param string $tag The name of the AJAX action to which the $method is hooked.
115114
* @param string $method Optional. The name of the method to be called. If the name of the method is not provided, tag name will be used as method name.
116115
* @param bool $methodClass The root of the method.
117-
* @param boolean $private Optional. Determines if we should register hook for logged in users.
118-
* @param boolean $public Optional. Determines if we should register hook for not logged in users.
116+
* @param boolean $logged_in Optional. Determines if we should register hook for logged in users.
117+
* @param boolean $logged_out Optional. Determines if we should register hook for not logged in users.
119118
* @return Visualizer_Module
120119
*/
121-
protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $private = true, $public = false ) {
122-
if ( $private ) {
120+
protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $logged_in = true, $logged_out = false ) {
121+
if ( $logged_in ) {
123122
$this->_addAction( 'wp_ajax_' . $tag, $method, $methodClass );
124123
}
125124

126-
if ( $public ) {
125+
if ( $logged_out ) {
127126
$this->_addAction( 'wp_ajax_nopriv_' . $tag, $method, $methodClass );
128127
}
129128

@@ -169,7 +168,7 @@ protected function _addShortcode( $tag, $method ) {
169168
*
170169
* @since 3.2.0
171170
*/
172-
public function getDataAs( $final, $chart_id, $type ) {
171+
public function getDataAs( $data, $chart_id, $type ) {
173172
return $this->_getDataAs( $chart_id, $type );
174173
}
175174

@@ -290,8 +289,8 @@ private function _getCSV( $rows, $filename, $enclose ) {
290289
}
291290
rewind( $fp );
292291
$csv = '';
293-
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
294-
while ( ( $array = fgetcsv( $fp ) ) !== false ) {
292+
$array = fgetcsv( $fp );
293+
while ( $array !== false ) {
295294
if ( strlen( $csv ) > 0 ) {
296295
$csv .= PHP_EOL;
297296
}
@@ -307,7 +306,8 @@ private function _getCSV( $rows, $filename, $enclose ) {
307306
}
308307
$array = $temp_array;
309308
}
310-
$csv .= implode( ',', $array );
309+
$csv .= implode( ',', $array );
310+
$array = fgetcsv( $fp );
311311
}
312312
fclose( $fp );
313313

@@ -333,7 +333,7 @@ private function _getExcel( $rows, $filename ) {
333333
unset( $rows[1] );
334334
$rows = array_values( $rows );
335335
$rows = array_map(
336-
function( $r ) {
336+
function ( $r ) {
337337
return array_map( 'strval', $r );
338338
},
339339
$rows
@@ -405,7 +405,7 @@ private function _getHTML( $rows ) {
405405
foreach ( $rows as $row ) {
406406
// skip the data type row.
407407
if ( 1 === $index ) {
408-
$index++;
408+
++$index;
409409
continue;
410410
}
411411

@@ -418,7 +418,7 @@ private function _getHTML( $rows ) {
418418
}
419419
}
420420
$table .= '</tr>';
421-
$index++;
421+
++$index;
422422
}
423423
$table .= '</table>';
424424

@@ -433,9 +433,9 @@ private function _getHTML( $rows ) {
433433
/**
434434
* Disable revisions temporarily for visualizer post type.
435435
*/
436-
protected final function disableRevisionsTemporarily() {
436+
final protected function disableRevisionsTemporarily() {
437437
add_filter(
438-
'wp_revisions_to_keep', function( $num, $post ) {
438+
'wp_revisions_to_keep', function ( $num, $post ) {
439439
if ( $post->post_type === Visualizer_Plugin::CPT_VISUALIZER ) {
440440
return 0;
441441
}
@@ -449,7 +449,7 @@ protected final function disableRevisionsTemporarily() {
449449
*
450450
* @return bool If any revisions were found.
451451
*/
452-
public final function undoRevisions( $chart_id, $restore = false ) {
452+
final public function undoRevisions( $chart_id, $restore = false ) {
453453
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'undoRevisions for %d with%s restore', $chart_id, ( $restore ? '' : 'out' ) ), 'debug', __FILE__, __LINE__ );
454454
if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
455455
return false;
@@ -481,7 +481,7 @@ public final function undoRevisions( $chart_id, $restore = false ) {
481481
/**
482482
* If existing revisions exist for the chart, restore the earliest version and then create a new revision to initiate editing.
483483
*/
484-
public final function handleExistingRevisions( $chart_id, $chart ) {
484+
final public function handleExistingRevisions( $chart_id, $chart ) {
485485

486486
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'handleExistingRevisions for %d', $chart_id ), 'debug', __FILE__, __LINE__ );
487487
if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
@@ -533,7 +533,7 @@ protected function get_user_customization_js() {
533533
}
534534

535535
try {
536-
require_once( ABSPATH . 'wp-admin/includes/file.php' );
536+
require_once ABSPATH . 'wp-admin/includes/file.php';
537537
WP_Filesystem();
538538
global $wp_filesystem;
539539
if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base' ) ) {
@@ -558,18 +558,18 @@ protected function get_user_customization_js() {
558558
}
559559

560560
if ( ! $wp_filesystem->exists( $dir ) ) {
561-
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
562-
if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) {
561+
$done = $wp_filesystem->mkdir( $dir );
562+
if ( $done === false ) {
563563
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
564564
return $default;
565565
}
566566
}
567567

568568
// if file does not exist, copy.
569569
if ( ! $wp_filesystem->exists( $file ) ) {
570-
$src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
571-
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
572-
if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) {
570+
$src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
571+
$done = $wp_filesystem->copy( $src, $file );
572+
if ( $done === false ) {
573573
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ );
574574
return $default;
575575
}
@@ -591,7 +591,7 @@ protected function load_chart_type( $chart_id ) {
591591
if ( 'Visualizer_Render_Sidebar_Type_DataTable_DataTable' === $name ) {
592592
$name = 'Visualizer_Render_Sidebar_Type_DataTable_Tabular';
593593
}
594-
$class = new $name;
594+
$class = new $name();
595595
}
596596

597597
if ( is_null( $class ) && Visualizer_Module::is_pro() ) {
@@ -752,7 +752,7 @@ public static function can_show_feature( $feature ) {
752752
/**
753753
* Gets the features for the provided license type.
754754
*/
755-
public static final function get_features_for_license( $plan ) {
755+
final public static function get_features_for_license( $plan ) {
756756
$is_new_personal = apply_filters( 'visualizer_is_new_personal', false );
757757
switch ( $plan ) {
758758
case 1:

classes/Visualizer/Module/AMP.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,4 @@ public function get_chart( $chart, $data, $series, $settings ) {
100100
}
101101
return $output['csv'];
102102
}
103-
104103
}

classes/Visualizer/Module/Admin.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,14 @@ public function __construct( Visualizer_Plugin $plugin ) {
9696
if ( defined( 'TI_E2E_TESTING' ) ) {
9797
$this->load_cypress_hooks();
9898
}
99-
10099
}
101100
/**
102101
* Display review notice.
103102
*/
104103
public function render_review_notice( $footer_text ) {
105104
$current_screen = get_current_screen();
106105

107-
$visualizer_page_ids = ['toplevel_page_visualizer', 'visualizer_page_viz-support', 'visualizer_page_ti-about-visualizer' ];
106+
$visualizer_page_ids = array( 'toplevel_page_visualizer', 'visualizer_page_viz-support', 'visualizer_page_ti-about-visualizer' );
108107

109108
if ( ! empty( $current_screen ) && isset( $current_screen->id ) ) {
110109
foreach ( $visualizer_page_ids as $page_to_check ) {
@@ -134,7 +133,7 @@ public function render_review_notice( $footer_text ) {
134133
private function load_cypress_hooks() {
135134
// all charts should load on the same page without pagination.
136135
add_filter(
137-
'visualizer_query_args', function( $args ) {
136+
'visualizer_query_args', function ( $args ) {
138137
$args['posts_per_page'] = 20;
139138
return $args;
140139
}, 10, 1
@@ -253,8 +252,7 @@ public function restoreRevision( $post_id, $revision_id ) {
253252
* @access public
254253
*/
255254
public function init() {
256-
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
257-
if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' == get_user_option( 'rich_editing' ) ) {
255+
if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' === get_user_option( 'rich_editing' ) ) {
258256
$this->_addFilter( 'mce_external_languages', 'add_tinymce_lang', 10, 1 );
259257
$this->_addFilter( 'mce_external_plugins', 'tinymce_plugin', 10, 1 );
260258
$this->_addFilter( 'mce_buttons', 'register_mce_button', 10, 1 );
@@ -268,7 +266,7 @@ public function init() {
268266
* @since ?
269267
* @access friendly
270268
*/
271-
function get_strings_for_block( $settings ) {
269+
public function get_strings_for_block( $settings ) {
272270
$class = new Visualizer_Module_Language();
273271
$strings = $class->get_strings();
274272
$array = array( 'visualizer_tinymce_plugin' => json_encode( $strings ) );
@@ -797,7 +795,7 @@ public function handleGetProSubMenu() {
797795
/**
798796
* Adds the screen options for pagination.
799797
*/
800-
function addScreenOptions() {
798+
public function addScreenOptions() {
801799
$screen = get_current_screen();
802800

803801
// bail if it's some other page.
@@ -816,7 +814,7 @@ function addScreenOptions() {
816814
/**
817815
* Returns the screen option for pagination.
818816
*/
819-
function setScreenOptions( $status, $option, $value ) {
817+
public function setScreenOptions( $status, $option, $value ) {
820818
if ( 'visualizer_library_per_page' === $option ) {
821819
return $value;
822820
}

classes/Visualizer/Module/Chart.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public function __construct( Visualizer_Plugin $plugin ) {
7070
$this->_addAjaxAction( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY, 'saveFilter' );
7171

7272
$this->_addFilter( 'visualizer_get_sidebar', 'getSidebar', 10, 2 );
73-
7473
}
7574

7675
/**
@@ -539,7 +538,8 @@ public function renderChartPages() {
539538
if ( ! empty( $_POST ) ) {
540539
$_POST = map_deep( $_POST, 'wp_strip_all_tags' );
541540
}
542-
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
541+
$chart = $chart_id ? get_post( $chart_id ) : null;
542+
if ( ! $chart_id || ! $chart || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
543543
if ( empty( $_GET['lang'] ) || empty( $_GET['parent_chart_id'] ) ) {
544544
$this->deleteOldCharts();
545545
$default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
@@ -738,7 +738,7 @@ private function loadCodeEditorAssets( $chart_id ) {
738738
wp_register_script( 'visualizer-codemirror-closebrackets', '//codemirror.net/addon/edit/closebrackets.js', array( 'visualizer-codemirror-core' ), Visualizer_Plugin::VERSION );
739739
wp_register_script( 'visualizer-codemirror-sql', '//codemirror.net/mode/sql/sql.js', array( 'visualizer-codemirror-core' ), Visualizer_Plugin::VERSION );
740740
wp_register_script( 'visualizer-codemirror-sql-hint', '//codemirror.net/addon/hint/sql-hint.js', array( 'visualizer-codemirror-core' ), Visualizer_Plugin::VERSION );
741-
wp_register_script( 'visualizer-codemirror-hint', '//codemirror.net/addon/hint/show-hint.js', array( 'visualizer-codemirror-sql', 'visualizer-codemirror-sql-hint', 'visualizer-codemirror-placeholder', 'visualizer-codemirror-matchbrackets', 'visualizer-codemirror-closebrackets' ), Visualizer_Plugin::VERSION );
741+
wp_register_script( 'visualizer-codemirror-hint', '//codemirror.net/addon/hint/show-hint.js', array( 'visualizer-codemirror-sql', 'visualizer-codemirror-sql-hint', 'visualizer-codemirror-placeholder', 'visualizer-codemirror-matchbrackets', 'visualizer-codemirror-closebrackets' ), Visualizer_Plugin::VERSION );
742742
wp_register_style( 'visualizer-codemirror-core', '//codemirror.net/lib/codemirror.css', array(), Visualizer_Plugin::VERSION );
743743
wp_register_style( 'visualizer-codemirror-hint', '//codemirror.net/addon/hint/show-hint.css', array( 'visualizer-codemirror-core' ), Visualizer_Plugin::VERSION );
744744

@@ -862,10 +862,8 @@ private function _handleDataAndSettingsPage() {
862862
array(
863863
'ajax' => array(
864864
'url' => admin_url( 'admin-ajax.php' ),
865-
'nonces' => array(
866-
),
867-
'actions' => array(
868-
),
865+
'nonces' => array(),
866+
'actions' => array(),
869867
),
870868
)
871869
);
@@ -1028,7 +1026,7 @@ private function handleCSVasString( $data, $editor_type ) {
10281026
}
10291027
$row = explode( ',', $row );
10301028
$row = array_map(
1031-
function( $r ) {
1029+
function ( $r ) {
10321030
return '' === $r ? ' ' : $r;
10331031
},
10341032
$row
@@ -1079,7 +1077,7 @@ private function handleTabularData() {
10791077
if ( empty( $type ) ) {
10801078
$exclude[] = $index;
10811079
}
1082-
$index++;
1080+
++$index;
10831081
}
10841082

10851083
// when N headers are being renamed, the number of headers increases by N
@@ -1156,9 +1154,10 @@ public function uploadData() {
11561154
// check chart, if chart exists
11571155
// do not use filter_input as it does not work for phpunit test cases, use filter_var instead
11581156
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
1157+
$chart = $chart_id ? get_post( $chart_id ) : null;
11591158
if (
11601159
! $chart_id ||
1161-
! ( $chart = get_post( $chart_id ) ) ||
1160+
! $chart ||
11621161
$chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ||
11631162
! current_user_can( 'edit_post', $chart_id )
11641163
) {
@@ -1214,8 +1213,7 @@ public function uploadData() {
12141213
if ( isset( $_POST['vz-import-time'] ) ) {
12151214
apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $remote_data, $_POST['vz-import-time'] );
12161215
}
1217-
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1218-
} elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
1216+
} elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] === 0 ) {
12191217
$source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
12201218
} elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) {
12211219
$source = $this->handleCSVasString( $_POST['chart_data'], $_POST['editor-type'] );

0 commit comments

Comments
 (0)