Skip to content

Commit

Permalink
phpcs: Ignore warnings where the code is correct or where the warning…
Browse files Browse the repository at this point in the history
… is not relevant.
  • Loading branch information
TobiasBg committed Jun 9, 2021
1 parent f53a666 commit f2f9f0b
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 19 deletions.
1 change: 1 addition & 0 deletions classes/class-controller.php
Expand Up @@ -89,6 +89,7 @@ protected function plugin_update_check() {
$current_plugin_options_db_version = TablePress::$model_options->get( 'plugin_options_db_version' );
if ( $current_plugin_options_db_version < TablePress::db_version ) {
// Allow more PHP execution time for update process.
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
@set_time_limit( 300 );

// Add TablePress capabilities to the WP_Roles objects, for new installations and all versions below 12.
Expand Down
6 changes: 4 additions & 2 deletions classes/class-import.php
Expand Up @@ -160,13 +160,13 @@ protected function import_html() {
* Don't expand external entities, see https://websec.io/2012/08/27/Preventing-XXE-in-PHP.html.
* Silence warnings as the function is deprecated in PHP 8, but can be necessary with LIBXML_NOENT being defined, see https://core.trac.wordpress.org/changeset/50714.
*/
@libxml_disable_entity_loader( true );
@libxml_disable_entity_loader( true ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
}
// No warnings/errors raised, but stored internally.
libxml_use_internal_errors( true );
$dom = new DOMDocument( '1.0', 'UTF-8' );
// No strict checking for invalid HTML.
$dom->strictErrorChecking = false;
$dom->strictErrorChecking = false; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$dom->loadHTML( $full_html );
if ( false === $dom ) {
$this->imported_table = false;
Expand Down Expand Up @@ -442,6 +442,7 @@ protected function fix_table_encoding() {

// Check for possible UTF-16 BOMs ("little endian" and "big endian") and try to convert the data to UTF-8.
if ( "\xFF\xFE" === substr( $this->import_data, 0, 2 ) || "\xFE\xFF" === substr( $this->import_data, 0, 2 ) ) {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$data = @iconv( 'UTF-16', 'UTF-8', $this->import_data );
if ( false !== $data ) {
$this->import_data = $data;
Expand All @@ -453,6 +454,7 @@ protected function fix_table_encoding() {
if ( function_exists( 'mb_detect_encoding' ) ) {
$current_encoding = mb_detect_encoding( $this->import_data, 'ASCII, UTF-8, ISO-8859-1' );
if ( 'UTF-8' !== $current_encoding ) {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$data = @iconv( $current_encoding, 'UTF-8', $this->import_data );
if ( false !== $data ) {
$this->import_data = $data;
Expand Down
2 changes: 1 addition & 1 deletion classes/class-view.php
Expand Up @@ -153,7 +153,7 @@ public function setup( $action, array $data ) {
if ( is_rtl() ) {
$this->admin_page->enqueue_style( 'common-rtl', array( 'tablepress-common' ) );
}
$this->admin_page->enqueue_script( 'common', array( 'jquery', 'postbox' ), array(
$this->admin_page->enqueue_script( 'common', array( 'jquery', 'postbox' ), array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
'common' => array(
'ays_delete_single_table' => _n( 'Do you really want to delete this table?', 'Do you really want to delete these tables?', 1, 'tablepress' ),
'ays_delete_multiple_tables' => _n( 'Do you really want to delete this table?', 'Do you really want to delete these tables?', 2, 'tablepress' ),
Expand Down
14 changes: 8 additions & 6 deletions controllers/controller-admin.php
Expand Up @@ -190,7 +190,7 @@ public function add_editor_buttons() {

add_thickbox(); // usually already loaded by media upload functions
$admin_page = TablePress::load_class( 'TablePress_Admin_Page', 'class-admin-page-helper.php', 'classes' );
$admin_page->enqueue_script( 'quicktags-button', array( 'quicktags', 'media-upload' ), array(
$admin_page->enqueue_script( 'quicktags-button', array( 'quicktags', 'media-upload' ), array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
'editor_button' => array(
'caption' => __( 'Table', 'tablepress' ),
'title' => __( 'Insert a Table from TablePress', 'tablepress' ),
Expand Down Expand Up @@ -939,8 +939,8 @@ public function handle_post_action_export() {
} else {
// Zipping can use a lot of memory and execution time, but not this much hopefully.
/** This filter is documented in the WordPress file wp-admin/admin.php */
@ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
@set_time_limit( 300 );
@ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
@set_time_limit( 300 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged

$zip_file = new ZipArchive();
$download_filename = sprintf( 'tablepress-export-%1$s-%2$s.zip', wp_date( 'Y-m-d-H-i-s' ), $export['format'] );
Expand Down Expand Up @@ -975,6 +975,7 @@ public function handle_post_action_export() {
}

// If something went wrong, or no files were added to the ZIP file, bail out.
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( ! ZIPARCHIVE::ER_OK === $zip_file->status || 0 === $zip_file->numFiles ) {
$zip_file->close();
@unlink( $full_filename );
Expand All @@ -998,7 +999,7 @@ public function handle_post_action_export() {
header( 'Content-Length: ' . strlen( $download_data ) );
// $filetype = text/csv, text/html, application/json
// header( 'Content-Type: ' . $filetype. '; charset=' . get_option( 'blog_charset' ) );
@ob_end_clean();
@ob_end_clean(); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
flush();
echo $download_data;
exit;
Expand Down Expand Up @@ -1141,8 +1142,8 @@ public function handle_post_action_import() {
} else {
// Zipping can use a lot of memory and execution time, but not this much hopefully.
/** This filter is documented in the WordPress file wp-admin/admin.php */
@ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
@set_time_limit( 300 );
@ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
@set_time_limit( 300 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged

$zip = new ZipArchive();
if ( true !== $zip->open( $import_data['file_location'], ZIPARCHIVE::CHECKCONS ) ) {
Expand All @@ -1165,6 +1166,7 @@ public function handle_post_action_import() {
}

$imported_files = array();
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
for ( $file_idx = 0; $file_idx < $zip->numFiles; $file_idx++ ) {
$file_name = $zip->getNameIndex( $file_idx );
// Skip directories.
Expand Down
6 changes: 6 additions & 0 deletions libraries/evalmath.class.php
Expand Up @@ -291,6 +291,7 @@ protected function nfx( $expression ) {
$index--;
}
// Heart of the algorithm:
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( $stack->count > 0 && ( $o2 = $stack->last() ) && in_array( $o2, $ops, true ) && ( $ops_r[ $op ] ? $ops_p[ $op ] < $ops_p[ $o2 ] : $ops_p[ $op ] <= $ops_p[ $o2 ] ) ) {
// Pop stuff off the stack into the output.
$output[] = $stack->pop();
Expand All @@ -303,6 +304,7 @@ protected function nfx( $expression ) {
// Ready to close a parenthesis?
} elseif ( ')' === $op && $expecting_operator ) {
// Pop off the stack back to the last (.
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( '(' !== ( $o2 = $stack->pop() ) ) {
if ( is_null( $o2 ) ) {
return $this->raise_error( 'unexpected_closing_bracket' );
Expand Down Expand Up @@ -351,6 +353,7 @@ protected function nfx( $expression ) {

// Did we just finish a function argument?
} elseif ( ',' === $op && $expecting_operator ) {
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( '(' !== ( $o2 = $stack->pop() ) ) {
if ( is_null( $o2 ) ) {
// Oops, never had a (.
Expand Down Expand Up @@ -454,6 +457,7 @@ protected function nfx( $expression ) {
} // while ( true )

// Pop everything off the stack and push onto output.
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( ! is_null( $op = $stack->pop() ) ) {
if ( '(' === $op ) {
// If there are (s on the stack, ()s were unbalanced.
Expand Down Expand Up @@ -500,6 +504,7 @@ protected function pfx( $tokens, array $variables = array() ) {
$function_name = 'log';
}
// Perfectly safe eval().
// phpcs:ignore Squiz.PHP.Eval.Discouraged
eval( '$stack->push( ' . $function_name . '( $op1 ) );' );

// Calc-emulation function.
Expand Down Expand Up @@ -586,6 +591,7 @@ protected function pfx( $tokens, array $variables = array() ) {
$stack->push( (int) ( $op1 < $op2 ) );
break;
case '=':
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
$stack->push( (int) ( $op1 == $op2 ) ); // Don't use === as the variable type can differ (int/double/bool).
break;
}
Expand Down
1 change: 1 addition & 0 deletions models/model-post.php
Expand Up @@ -274,6 +274,7 @@ public function load_posts( array $all_post_ids, $update_meta_cache = true ) {
$post_ids = _get_non_cached_ids( $post_ids, 'posts' );
if ( ! empty( $post_ids ) ) {
$post_ids_list = implode( ',', $post_ids );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$posts = $wpdb->get_results( "SELECT {$wpdb->posts}.* FROM {$wpdb->posts} WHERE ID IN ({$post_ids_list})" );
update_post_cache( $posts );
if ( $update_meta_cache ) {
Expand Down
4 changes: 4 additions & 0 deletions tests/test-utils.php
Expand Up @@ -60,6 +60,7 @@ public function test_letter_to_number( $letter, $number ) {
* @return array Test data.
*/
public function data_letter_to_number() {
// phpcs:disable WordPress.Arrays.CommaAfterArrayItem.SpaceAfterComma, WordPress.Arrays.ArrayDeclarationSpacing.SpaceAfterArrayOpener
return array(
array( '', 0 ),
array( 'a', 1 ),
Expand All @@ -75,6 +76,7 @@ public function data_letter_to_number() {
array( 'ZZZ', 18278 ),
array( 'zzz', 18278 ),
);
// phpcs:enable
}

/**
Expand All @@ -99,6 +101,7 @@ public function test_number_to_letter( $number, $letter ) {
* @return array Test data.
*/
public function data_number_to_letter() {
// phpcs:disable WordPress.Arrays.CommaAfterArrayItem.SpaceAfterComma, WordPress.Arrays.ArrayDeclarationSpacing.SpaceAfterArrayOpener
return array(
array( -1, '' ),
array( 0, '' ),
Expand All @@ -110,6 +113,7 @@ public function data_number_to_letter() {
array( 703, 'AAA' ),
array( 18278, 'ZZZ' ),
);
// phpcs:enable
}

/**
Expand Down
6 changes: 3 additions & 3 deletions views/view-about.php
Expand Up @@ -183,12 +183,12 @@ public function postbox_debug_version_information( array $data, array $box ) {
<br />&middot; Multisite: <?php echo is_multisite() ? 'yes' : 'no'; ?>
<br />&middot; PHP: <?php echo phpversion(); ?>
<br />&middot; mysqli Extension: <?php echo $mysqli ? 'true' : 'false'; ?>
<br />&middot; mySQL (Server): <?php echo $mysqli ? mysqli_get_server_info( $GLOBALS['wpdb']->dbh ) : '<em>no mysqli</em>'; ?>
<br />&middot; mySQL (Client): <?php echo $mysqli ? mysqli_get_client_info( $GLOBALS['wpdb']->dbh ) : '<em>no mysqli</em>'; ?>
<br />&middot; mySQL (Server): <?php echo $mysqli ? mysqli_get_server_info( $GLOBALS['wpdb']->dbh ) : '<em>no mysqli</em>'; // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_server_info ?>
<br />&middot; mySQL (Client): <?php echo $mysqli ? mysqli_get_client_info( $GLOBALS['wpdb']->dbh ) : '<em>no mysqli</em>'; // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_client_info ?>
<br />&middot; ZIP support: <?php echo $data['zip_support_available'] ? 'yes' : 'no'; ?>
<br />&middot; UTF-8 conversion: <?php echo ( function_exists( 'mb_detect_encoding' ) && function_exists( 'iconv' ) ) ? 'yes' : 'no'; ?>
<br />&middot; WP Memory Limit: <?php echo WP_MEMORY_LIMIT; ?>
<br />&middot; Server Memory Limit: <?php echo (int) @ini_get( 'memory_limit' ) . 'M'; ?>
<br />&middot; Server Memory Limit: <?php echo (int) @ini_get( 'memory_limit' ) . 'M'; // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged ?>
<br />&middot; WP_DEBUG: <?php echo WP_DEBUG ? 'true' : 'false'; ?>
<br />&middot; WP_POST_REVISIONS: <?php echo is_bool( WP_POST_REVISIONS ) ? ( WP_POST_REVISIONS ? 'true' : 'false' ) : WP_POST_REVISIONS; ?>
</p>
Expand Down
4 changes: 2 additions & 2 deletions views/view-edit.php
Expand Up @@ -73,7 +73,7 @@ public function setup( $action, array $data ) {
wp_enqueue_script( 'wplink' );

$this->admin_page->enqueue_style( 'edit' );
$this->admin_page->enqueue_script( 'edit', array( 'jquery', 'jquery-ui-sortable' ), array(
$this->admin_page->enqueue_script( 'edit', array( 'jquery', 'jquery-ui-sortable' ), array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
'options' => array(
/**
* Filter whether debug output shall be printed to the page.
Expand Down Expand Up @@ -691,7 +691,7 @@ public function wp_pointer_tp09_edit_drag_drop_sort() {
$content = '<h3>' . __( 'TablePress Feature: Moving rows and columns', 'tablepress' ) . '</h3>';
$content .= '<p>' . __( 'Did you know? You can drag and drop rows and columns via the row number and the column title. And the arrows next to the column title can be used for sorting.', 'tablepress' ) . '</p>';

$this->admin_page->print_wp_pointer_js( 'tp09_edit_drag_drop_sort', '#edit-form-head', array(
$this->admin_page->print_wp_pointer_js( 'tp09_edit_drag_drop_sort', '#edit-form-head', array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
'content' => $content,
'position' => array( 'edge' => 'top', 'align' => 'left', 'offset' => '56 2' ),
) );
Expand Down
4 changes: 2 additions & 2 deletions views/view-list.php
Expand Up @@ -40,7 +40,7 @@ public function setup( $action, array $data ) {
parent::setup( $action, $data );

add_thickbox();
$this->admin_page->enqueue_script( 'list', array( 'jquery' ), array(
$this->admin_page->enqueue_script( 'list', array( 'jquery' ), array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
'list' => array(
'shortcode_popup' => __( 'To embed this table into a post or page, use this Shortcode:', 'tablepress' ),
'donation-message-already-donated' => __( 'Thank you very much! Your donation is highly appreciated. You just contributed to the further development of TablePress!', 'tablepress' ),
Expand Down Expand Up @@ -578,7 +578,7 @@ protected function bulk_actions( $which = '' ) {
$this->_actions = $this->get_bulk_actions();
$no_new_actions = $this->_actions;
/** This filter is documented in the WordPress function WP_List_Table::bulk_actions() in wp-admin/includes/class-wp-list-table.php */
$this->_actions = apply_filters( 'bulk_actions-' . $this->screen->id, $this->_actions );
$this->_actions = apply_filters( 'bulk_actions-' . $this->screen->id, $this->_actions ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
$this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
$two = '';
} else {
Expand Down
6 changes: 3 additions & 3 deletions views/view-options.php
Expand Up @@ -35,13 +35,13 @@ public function setup( $action, array $data ) {
$codemirror_settings = wp_enqueue_code_editor( array( 'type' => 'text/css' ) );
if ( ! empty( $codemirror_settings ) ) {
// Load CSS adjustments for CodeMirror and the added vertical resizing.
$this->admin_page->enqueue_style( 'codemirror', array( 'code-editor' ) );
$this->admin_page->enqueue_script( 'codemirror', array( 'jquery', 'jquery-ui-resizable' ), array(
$this->admin_page->enqueue_style( 'codemirror', array( 'code-editor' ) ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
$this->admin_page->enqueue_script( 'codemirror', array( 'jquery', 'jquery-ui-resizable' ), array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
'codemirror_settings' => $codemirror_settings,
) );
}

$this->admin_page->enqueue_script( 'options', array( 'jquery' ), array(
$this->admin_page->enqueue_script( 'options', array( 'jquery' ), array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
'strings' => array(
'uninstall_warning_1' => __( 'Do you really want to uninstall TablePress and delete ALL data?', 'tablepress' ),
'uninstall_warning_2' => __( 'Are you really sure?', 'tablepress' ),
Expand Down

0 comments on commit f2f9f0b

Please sign in to comment.