Skip to content

Commit

Permalink
PHPCS: Fix a bunch of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JJJ committed Jun 18, 2024
1 parent 959523a commit b734ca9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 54 deletions.
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
49 changes: 25 additions & 24 deletions ludicrousdb/drop-ins/db-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*
Expand All @@ -32,57 +30,56 @@
$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
*/
$wpdb->save_queries = false;

/**
* recheck_timeout (float)
* The amount of time to wait before trying again to ping mysql server.
*
* Default: 0.1 (Seconds)
*/
$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';
Expand All @@ -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,
)
);
4 changes: 2 additions & 2 deletions ludicrousdb/drop-ins/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
47 changes: 24 additions & 23 deletions ludicrousdb/includes/class-ludicrousdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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'];
}
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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' );
Expand Down Expand Up @@ -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 ];
}
}

Expand Down Expand Up @@ -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 );
}
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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++;
}
}

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) ) {
Expand Down Expand Up @@ -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}" );
}
Expand Down Expand Up @@ -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
Expand All @@ -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 );
}
Expand Down Expand Up @@ -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,
);
}

Expand Down Expand Up @@ -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 ] );
}
Expand Down
2 changes: 0 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<exclude name="Squiz.Commenting.FileComment" />
<exclude name="Squiz.PHP.CommentedOutCode.Found" />
<exclude name="Squiz.PHP.DisallowMultipleAssignments" />
<exclude name="WordPress.CodeAnalysis.AssignmentInCondition" />
<exclude name="WordPress.DB.RestrictedFunctions" />
<exclude name="WordPress.PHP.DontExtract.extract_extract" />
<exclude name="WordPress.PHP.DevelopmentFunctions.error_log_wp_debug_backtrace_summary" />
Expand All @@ -35,7 +34,6 @@
<property name="text_domain" type="array">
<element value="ludicrousdb" />
</property>
<property name="check_translator_comments" value="true" />
</properties>
</rule>
<rule ref="PHPCompatibilityWP">
Expand Down

0 comments on commit b734ca9

Please sign in to comment.