diff --git a/ludicrousdb/includes/class-ludicrousdb.php b/ludicrousdb/includes/class-ludicrousdb.php index baf3973..cb1aea8 100644 --- a/ludicrousdb/includes/class-ludicrousdb.php +++ b/ludicrousdb/includes/class-ludicrousdb.php @@ -3,6 +3,9 @@ /** * LudicrousDB Class * + * Disable this check for the file, since we explicitly overwrite default WP db behavior, so this error is always a false positive in this file + * phpcs:disable WordPress.DB.RestrictedFunctions + * * @package Plugins/LudicrousDB/Class */ @@ -433,7 +436,7 @@ public function send_reads_to_masters() { */ public function run_callbacks( $group, $args = null ) { if ( ! isset( $this->ludicrous_callbacks[ $group ] ) || ! is_array( $this->ludicrous_callbacks[ $group ] ) ) { - return null; + return; } if ( ! isset( $args ) ) { @@ -599,8 +602,9 @@ public function db_connect( $query = '' ) { $this->current_host = $this->dbh2host[ $dbhname ]; // Keep this connection at the top of the stack to prevent disconnecting frequently-used connections - if ( $k = array_search( $dbhname, $this->open_connections, true ) ) { - unset( $this->open_connections[ $k ] ); + $key = array_search( $dbhname, $this->open_connections, true ); + if ( $key !== false ) { + unset( $this->open_connections[ $key ] ); $this->open_connections[] = $dbhname; } @@ -650,7 +654,8 @@ public function db_connect( $query = '' ) { } } - if ( ! $tries_remaining = count( $servers ) ) { + $tries_remaining = count( $servers ); + if ( $tries_remaining === 0 ) { return $this->bail( "No database servers were found to match the query. ({$this->table}, {$dataset})" ); } @@ -727,7 +732,7 @@ 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 ) { // 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 ) { @@ -1151,13 +1156,12 @@ public function set_charset( $dbh, $charset = null, $collate = null ) { * * @since 1.0.0 * - * @param string $dbhname Dataname key name. + * @param string $dbhname Database name. */ public function disconnect( $dbhname ) { - - $k = array_search( $dbhname, $this->open_connections, true ); - if ( ! empty( $k ) ) { - unset( $this->open_connections[ $k ] ); + $key = array_search( $dbhname, $this->open_connections, true ); + if ( $key !== false ) { + unset( $this->open_connections[ $key ] ); } if ( $this->dbh_type_check( $this->dbhs[ $dbhname ] ) ) { @@ -1746,7 +1750,7 @@ private function get_db_object( $dbh_or_table = false ) { } /** - * Check databse object type. + * Check database object type. * * @param resource|mysqli $dbh Database resource. *