From b734ca9e45ae419ea0cf586e8b577609fac7f1ef Mon Sep 17 00:00:00 2001 From: John James Jacoby Date: Tue, 18 Jun 2024 15:02:48 -0500 Subject: [PATCH] PHPCS: Fix a bunch of errors --- composer.json | 8 ++-- ludicrousdb/drop-ins/db-config.php | 49 +++++++++++----------- ludicrousdb/drop-ins/db.php | 4 +- ludicrousdb/includes/class-ludicrousdb.php | 47 +++++++++++---------- phpcs.xml | 2 - 5 files changed, 56 insertions(+), 54 deletions(-) diff --git a/composer.json b/composer.json index 8ea1a65..2b0cd99 100644 --- a/composer.json +++ b/composer.json @@ -23,10 +23,12 @@ "composer/installers": "~1.0 || ~2.0" }, "require-dev": { - "wp-coding-standards/wpcs": "^2.3", - "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", + "wp-coding-standards/wpcs": "^3.1", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "phpcompatibility/phpcompatibility-wp": "^2.1", - "sirbrillig/phpcs-variable-analysis": "^2.8" + "sirbrillig/phpcs-variable-analysis": "^2.8", + "squizlabs/php_codesniffer": "^3.10", + "phpcompatibility/php-compatibility": "^9.3" }, "scripts": { "format": [ diff --git a/ludicrousdb/drop-ins/db-config.php b/ludicrousdb/drop-ins/db-config.php index 491618a..0ad5f89 100644 --- a/ludicrousdb/drop-ins/db-config.php +++ b/ludicrousdb/drop-ins/db-config.php @@ -13,7 +13,6 @@ defined( 'ABSPATH' ) || exit; /** - * charset (string) * This sets the default character set. Since WordPress 4.2, the suggested * setting is "utf8mb4". We strongly recommend not downgrading to utf8, * using latin1, or sticking to the default: utf8mb4. @@ -23,7 +22,6 @@ $wpdb->charset = 'utf8mb4'; /** - * collate (string) * This sets the default column collation. For best results, investigate which * collation is recommended for your specific character set. * @@ -32,7 +30,6 @@ $wpdb->collate = 'utf8mb4_unicode_520_ci'; /** - * save_queries (bool) * This is useful for debugging. Queries are saved in $wpdb->queries. It is not * a constant because you might want to use it momentarily. * Default: false @@ -40,7 +37,6 @@ $wpdb->save_queries = false; /** - * recheck_timeout (float) * The amount of time to wait before trying again to ping mysql server. * * Default: 0.1 (Seconds) @@ -48,41 +44,42 @@ $wpdb->recheck_timeout = 0.1; /** - * persistent (bool) * This determines whether to use mysql_connect or mysql_pconnect. The effects * of this setting may vary and should be carefully tested. + * * Default: false */ $wpdb->persistent = false; /** - * allow_bail (bool) * This determines whether to use mysql connect or mysql connect has failed and to bail loading the rest of WordPress + * * Default: false */ $wpdb->allow_bail = false; /** - * max_connections (int) * This is the number of mysql connections to keep open. Increase if you expect * to reuse a lot of connections to different servers. This is ignored if you * enable persistent connections. + * * Default: 10 */ $wpdb->max_connections = 10; /** - * check_tcp_responsiveness * Enables checking TCP responsiveness by fsockopen prior to mysql_connect or * mysql_pconnect. This was added because PHP's mysql functions do not provide * a variable timeout setting. Disabling it may improve average performance by * a very tiny margin but lose protection against connections failing slowly. + * * Default: true */ $wpdb->check_tcp_responsiveness = true; /** * The cache group that is used to store TCP responsiveness. + * * Default: ludicrousdb */ $wpdb->cache_group = 'ludicrousdb'; @@ -93,24 +90,28 @@ * This adds the DB defined in wp-config.php as a read/write server for * the 'global' dataset. (Every table is in 'global' by default.) */ -$wpdb->add_database( array( - 'host' => DB_HOST, // If port is other than 3306, use host:port. - 'user' => DB_USER, - 'password' => DB_PASSWORD, - 'name' => DB_NAME, -) ); +$wpdb->add_database( + array( + 'host' => DB_HOST, // If port is other than 3306, use host:port. + 'user' => DB_USER, + 'password' => DB_PASSWORD, + 'name' => DB_NAME, + ) +); /** * This adds the same server again, only this time it is configured as a slave. * The last three parameters are set to the defaults but are shown for clarity. */ -$wpdb->add_database( array( - 'host' => DB_HOST, // If port is other than 3306, use host:port. - 'user' => DB_USER, - 'password' => DB_PASSWORD, - 'name' => DB_NAME, - 'write' => 0, - 'read' => 1, - 'dataset' => 'global', - 'timeout' => 0.2, -) ); +$wpdb->add_database( + array( + 'host' => DB_HOST, // If port is other than 3306, use host:port. + 'user' => DB_USER, + 'password' => DB_PASSWORD, + 'name' => DB_NAME, + 'write' => 0, + 'read' => 1, + 'dataset' => 'global', + 'timeout' => 0.2, + ) +); diff --git a/ludicrousdb/drop-ins/db.php b/ludicrousdb/drop-ins/db.php index e2e0478..418d96b 100644 --- a/ludicrousdb/drop-ins/db.php +++ b/ludicrousdb/drop-ins/db.php @@ -26,10 +26,10 @@ defined( 'ABSPATH' ) || exit; // Custom directory name -$ldb_dirname = defined( 'LDB_DIRNAME' ) ? LDB_DIRNAME : 'ludicrousdb'; +$ldb_dirname = defined( 'LDB_DIRNAME' ) ? LDB_DIRNAME : 'ludicrousdb'; // Supported plugin directories -$wp_plugin_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins'; +$wp_plugin_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins'; $wpmu_plugin_dir = defined( 'WPMU_PLUGIN_DIR' ) ? WPMU_PLUGIN_DIR : WP_CONTENT_DIR . '/mu-plugins'; $wpdb_plugin_dir = defined( 'WPDB_PLUGIN_DIR' ) ? WPDB_PLUGIN_DIR : WP_CONTENT_DIR . '/db-plugins'; diff --git a/ludicrousdb/includes/class-ludicrousdb.php b/ludicrousdb/includes/class-ludicrousdb.php index 5c426ec..16e2a8f 100644 --- a/ludicrousdb/includes/class-ludicrousdb.php +++ b/ludicrousdb/includes/class-ludicrousdb.php @@ -261,7 +261,7 @@ public function __construct( $dbuser = '', $dbpassword = '', $dbname = '', $dbho if ( is_array( $dbuser ) ) { $class_vars = $dbuser; - // WPDB style parameter pattern + // WPDB style parameter pattern } elseif ( is_string( $dbuser ) ) { // Only compact if all params are not empty @@ -496,7 +496,7 @@ public function db_connect( $query = '' ) { $dataset = $this->ludicrous_tables[ $this->table ]; $this->callback_result = null; - // Run callbacks and either extract or update dataset + // Run callbacks and either extract or update dataset } else { // Run callbacks and get result @@ -546,7 +546,7 @@ public function db_connect( $query = '' ) { } // Determine whether the query must be sent to the master (a writable server) - if ( ! empty( $use_master ) || ( $this->srtm === true ) || isset( $this->srtm[ $this->table ] ) ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable + if ( ! empty( $use_master ) || ( true === $this->srtm ) || isset( $this->srtm[ $this->table ] ) ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable $use_master = true; } elseif ( $this->is_write_query( $query ) ) { $use_master = true; @@ -615,7 +615,7 @@ public function db_connect( $query = '' ) { $this->used_servers[ $dbhname ]['name'] = $name; } - // Otherwise, use the name from the last connection + // Otherwise, use the name from the last connection } else { $name = $this->used_servers[ $dbhname ]['name']; } @@ -684,7 +684,7 @@ public function db_connect( $query = '' ) { $success = false; foreach ( $servers as $group_key ) { - -- $tries_remaining; + --$tries_remaining; // If all servers are lagged, we need to start ignoring the lag and retry if ( count( $unique_lagged_slaves ) == $this->unique_servers ) { @@ -716,7 +716,7 @@ public function db_connect( $query = '' ) { if ( ! empty( $server ) && is_array( $server ) ) { extract( $server, EXTR_OVERWRITE ); - // Otherwise, set $server to an empty array + // Otherwise, set $server to an empty array } else { $server = array(); } @@ -809,7 +809,7 @@ public function db_connect( $query = '' ) { $this->dbh2host[ $dbhname ] = $host_and_port; // Define these to avoid undefined variable notices - $queries = isset( $queries ) ? $queries : 1; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable + $queries = isset( $queries ) ? $queries : 1; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable $lag = isset( $this->lag ) ? $this->lag : 0; $this->last_connection = compact( 'dbhname', 'host', 'port', 'user', 'name', 'tcp', 'elapsed', 'success', 'queries', 'lag' ); @@ -924,7 +924,7 @@ protected function increment_db_connection( $connection = 0, $name = '' ) { if ( ! isset( $this->db_connections[ $connection ][ $name ] ) ) { $this->db_connections[ $connection ][ $name ] = 1; } else { - ++ $this->db_connections[ $connection ][ $name ]; + ++$this->db_connections[ $connection ][ $name ]; } } @@ -1098,7 +1098,7 @@ protected function load_col_info() { $num_fields = mysqli_num_fields( $this->result ); - for ( $i = 0; $i < $num_fields; $i ++ ) { + for ( $i = 0; $i < $num_fields; $i++ ) { $this->col_info[ $i ] = mysqli_fetch_field( $this->result ); } } @@ -1249,7 +1249,7 @@ public function check_connection( $allow_bail = true, $dbh_or_table = false, $qu error_reporting( $error_reporting & ~E_WARNING ); } - for ( $tries = 1; $tries <= $this->reconnect_retries; $tries ++ ) { + for ( $tries = 1; $tries <= $this->reconnect_retries; $tries++ ) { // On the last try, re-enable warnings. We want to see a single instance of the // "unable to connect" message on the bail() screen, if it appears. @@ -1409,14 +1409,14 @@ public function query( $query ) { $this->result = $this->_do_query( $query, $this->dbh ); $elapsed = $this->timer_stop(); - ++ $this->num_queries; + ++$this->num_queries; if ( preg_match( '/^\s*SELECT\s+([A-Z_]+\s+)*SQL_CALC_FOUND_ROWS\s/i', $query ) ) { if ( false === strpos( $query, 'NO_SELECT_FOUND_ROWS' ) ) { $this->timer_start(); $this->last_found_rows_result = $this->_do_query( 'SELECT FOUND_ROWS()', $this->dbh ); $elapsed += $this->timer_stop(); - ++ $this->num_queries; + ++$this->num_queries; $query .= '; SELECT FOUND_ROWS()'; } } else { @@ -1468,7 +1468,7 @@ public function query( $query ) { while ( $row = mysqli_fetch_object( $this->result ) ) { $this->last_result[ $num_rows ] = $row; - $num_rows ++; + $num_rows++; } } @@ -1505,8 +1505,9 @@ public function query( $query ) { * @access protected * @see wpdb::query() * - * @param string $query The query to run. - * @param bool $dbh_or_table Database or table name. Defaults to false. + * @param string $query The query to run. + * @param bool $dbh_or_table Database or table name. Defaults to false. + * @throws Throwable If the query fails. */ protected function _do_query( $query, $dbh_or_table = false ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore $dbh = $this->get_db_object( $dbh_or_table ); @@ -1647,7 +1648,7 @@ public function has_cap( $db_cap, $dbh_or_table = false ) { ) { // Strip the '5.5.5-' prefix and set the version to the correct value. $db_server_info = preg_replace( '/^5\.5\.5-(.*)/', '$1', $db_server_info ); - $db_version = preg_replace( '/[^0-9.].*/', '', $db_server_info ); + $db_version = preg_replace( '/[^0-9.].*/', '', $db_server_info ); } switch ( strtolower( $db_cap ) ) { @@ -1763,11 +1764,11 @@ private function get_db_object( $dbh_or_table = false ) { if ( $this->dbh_type_check( $dbh_or_table ) ) { $dbh = &$dbh_or_table; - // Database + // Database } elseif ( ( false === $dbh_or_table ) && $this->dbh_type_check( $this->dbh ) ) { $dbh = &$this->dbh; - // Table name + // Table name } elseif ( is_string( $dbh_or_table ) ) { $dbh = $this->db_connect( "SELECT FROM {$dbh_or_table} {$this->users}" ); } @@ -2206,7 +2207,7 @@ protected function tcp_cache_get( $key = '' ) { if ( $this->tcp_is_cache_persistent() ) { return wp_cache_get( $key, $this->cache_group ); - // Fallback to local cache + // Fallback to local cache } elseif ( ! empty( $this->tcp_cache[ $key ] ) ) { // Not expired @@ -2217,7 +2218,7 @@ protected function tcp_cache_get( $key = '' ) { ? $this->tcp_cache[ $key ]['value'] : false; - // Expired, so delete and proceed + // Expired, so delete and proceed } else { $this->tcp_cache_delete( $key ); } @@ -2252,11 +2253,11 @@ protected function tcp_cache_set( $key = '', $value = '' ) { if ( $this->tcp_is_cache_persistent() ) { return wp_cache_set( $key, $value, $this->cache_group, $expires ); - // Fallback to local cache + // Fallback to local cache } else { $this->tcp_cache[ $key ] = array( 'value' => $value, - 'expiration' => time() + $expires + 'expiration' => time() + $expires, ); } @@ -2285,7 +2286,7 @@ protected function tcp_cache_delete( $key = '' ) { if ( $this->tcp_is_cache_persistent() ) { return wp_cache_delete( $key, $this->cache_group ); - // Fallback to local cache + // Fallback to local cache } else { unset( $this->tcp_cache[ $key ] ); } diff --git a/phpcs.xml b/phpcs.xml index 8146c63..c9064ab 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -14,7 +14,6 @@ - @@ -35,7 +34,6 @@ -