Skip to content

Commit

Permalink
PHPCS: Fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JJJ committed Jun 18, 2024
1 parent 10a3de6 commit db8b471
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions ludicrousdb/includes/class-ludicrousdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LudicrousDB extends wpdb {
/**
* The last table that was queried
*
* @var string
* @var string Default empty string.
*/
public $last_table = '';

Expand All @@ -33,21 +33,21 @@ class LudicrousDB extends wpdb {
* intervening queries from making FOUND_ROWS() inaccessible. You may
* prevent this by adding "NO_SELECT_FOUND_ROWS" in a comment
*
* @var resource
* @var resource Default null.
*/
public $last_found_rows_result = null;

/**
* Whether to store queries in an array. Useful for debugging and profiling
*
* @var bool
* @var bool Default false.
*/
public $save_queries = false;

/**
* The current MySQL link resource
*
* @var mysqli|resource|false|null
* @var mysqli|resource|false|null Default null.
*/
public $dbh;

Expand All @@ -61,78 +61,78 @@ class LudicrousDB extends wpdb {
/**
* The multi-dimensional array of datasets and servers
*
* @var array
* @var array Default empty array.
*/
public $ludicrous_servers = array();

/**
* Optional directory of tables and their datasets
*
* @var array
* @var array Default empty array.
*/
public $ludicrous_tables = array();

/**
* Optional directory of callbacks to determine datasets from queries
*
* @var array
* @var array Default empty array.
*/
public $ludicrous_callbacks = array();

/**
* Custom callback to save debug info in $this->queries
*
* @var callable
* @var callable Default null.
*/
public $save_query_callback = null;

/**
* Whether to use mysql_pconnect instead of mysql_connect
*
* @var bool
* @var bool Default false.
*/
public $persistent = false;

/**
* Allow bail if connection fails
*
* @var bool
* @var bool Default false.
*/
public $allow_bail = false;

/**
* The maximum number of db links to keep open. The least-recently used
* link will be closed when the number of links exceeds this
*
* @var int
* @var int Default 10.
*/
public $max_connections = 10;

/**
* Whether to check with fsockopen prior to mysql_connect
*
* @var bool
* @var bool Default true.
*/
public $check_tcp_responsiveness = true;

/**
* The amount of time to wait before trying again to ping mysql server.
*
* @var float
* @var float Default 0.1.
*/
public $recheck_timeout = 0.1;

/**
* Whether to check for heartbeats
*
* @var bool
* @var bool Default true.
*/
public $check_dbh_heartbeats = true;

/**
* Keeps track of the dbhname usage and errors.
*
* @var array
* @var array Default empty array.
*/
public $dbhname_heartbeats = array();

Expand All @@ -141,94 +141,94 @@ class LudicrousDB extends wpdb {
*
* @access protected
* @see wpdb::check_connection()
* @var int
* @var int Default 3.
*/
protected $reconnect_retries = 3;

/**
* Send Reads To Masters. This disables slave connections while true.
* Otherwise it is an array of written tables
*
* @var array
* @var array Default empty array.
*/
public $srtm = array();

/**
* The log of db connections made and the time each one took
*
* @var array
* @var array Default empty array.
*/
public $db_connections = array();

/**
* The list of unclosed connections sorted by LRU
*
* @var array
* @var array Default empty array.
*/
public $open_connections = array();

/**
* Lookup array (dbhname => host:port)
*
* @var array
* @var array Default empty array.
*/
public $dbh2host = array();

/**
* The last server used and the database name selected
*
* @var array
* @var array Default empty array.
*/
public $last_used_server = array();

/**
* Lookup array (dbhname => (server, db name) ) for re-selecting the db
* when a link is re-used
*
* @var array
* @var array Default empty array.
*/
public $used_servers = array();

/**
* Whether to save debug_backtrace in save_query_callback. You may wish
* to disable this, e.g. when tracing out-of-memory problems.
*
* @var bool
* @var bool Default true.
*/
public $save_backtrace = true;

/**
* Maximum lag in seconds. Set null to disable. Requires callbacks
*
* @var integer
* @var integer Default null.
*/
public $default_lag_threshold = null;

/**
* In memory cache for tcp connected status.
*
* @var array
* @var array Default empty array.
*/
private $tcp_cache = array();

/**
* Name of object cache group.
*
* @var string
* @var string Default 'ludicrousdb'.
*/
public $cache_group = 'ludicrousdb';

/**
* Whether to ignore slave lag.
*
* @var bool
* @var bool Default false.
*/
private $ignore_slave_lag = false;

/**
* Number of unique servers.
*
* @var int
* @var null|int Default null. Might be zero or more.
*/
private $unique_servers = null;

Expand Down Expand Up @@ -687,7 +687,7 @@ public function db_connect( $query = '' ) {
--$tries_remaining;

// If all servers are lagged, we need to start ignoring the lag and retry
if ( count( $unique_lagged_slaves ) == $this->unique_servers ) {
if ( count( $unique_lagged_slaves ) === (int) $this->unique_servers ) {
break;
}

Expand Down Expand Up @@ -750,10 +750,22 @@ public function db_connect( $query = '' ) {
: $this->default_lag_threshold;

// Check for a lagged slave, if applicable
if ( empty( $use_master ) && empty( $write ) && empty( $this->ignore_slave_lag ) && isset( $this->lag_threshold ) && ! isset( $server['host'] ) && ( $lagged_status = $this->get_lag_cache() ) === DB_LAG_BEHIND ) {
if (
empty( $use_master )
&&
empty( $write )
&&
empty( $this->ignore_slave_lag )
&&
isset( $this->lag_threshold )
&&
! isset( $server['host'] )
&&
( $lagged_status = $this->get_lag_cache() ) === DB_LAG_BEHIND // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition
) {

// If it is the last lagged slave and it is with the best preference we will ignore its lag
if ( ! isset( $unique_lagged_slaves[ $host_and_port ] ) && $this->unique_servers == count( $unique_lagged_slaves ) + 1 && $group == $min_group ) {
if ( ! isset( $unique_lagged_slaves[ $host_and_port ] ) && ( (int) $this->unique_servers === count( $unique_lagged_slaves ) + 1 ) && $group == $min_group ) {

Check warning on line 768 in ludicrousdb/includes/class-ludicrousdb.php

View workflow job for this annotation

GitHub Actions / phpcs

Loose comparisons are not allowed. Expected: "==="; Found: "=="
$this->lag_threshold = null;
} else {
$unique_lagged_slaves[ $host_and_port ] = $this->lag;
Expand Down Expand Up @@ -791,7 +803,7 @@ public function db_connect( $query = '' ) {
&& ( $lagged_status = $this->get_lag() ) === DB_LAG_BEHIND

Check warning on line 803 in ludicrousdb/includes/class-ludicrousdb.php

View workflow job for this annotation

GitHub Actions / phpcs

Found precision alignment of 1 spaces.

Check warning on line 803 in ludicrousdb/includes/class-ludicrousdb.php

View workflow job for this annotation

GitHub Actions / phpcs

Variable assignment found within a condition. Did you mean to do a comparison ?
&& ! (
! isset( $unique_lagged_slaves[ $host_and_port ] )
&& ( $this->unique_servers == ( count( $unique_lagged_slaves ) + 1 ) )
&& ( (int) $this->unique_servers === ( count( $unique_lagged_slaves ) + 1 ) )
&& ( $group == $min_group )
)
) {
Expand Down

0 comments on commit db8b471

Please sign in to comment.