From e2de1af91009ac8bbcf9ec369753d883b515203b Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Wed, 18 Dec 2024 22:46:57 +0000 Subject: [PATCH] Remove $GLOBALS['cached_affected_rows'] Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 6 ------ src/DatabaseInterface.php | 7 +++++-- src/Server/Status/Monitor.php | 4 +--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4c6e32e1b1..2c4fa66162 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6957,12 +6957,6 @@ parameters: count: 1 path: src/DatabaseInterface.php - - - message: '#^Method PhpMyAdmin\\DatabaseInterface\:\:affectedRows\(\) should return int\|numeric\-string but returns mixed\.$#' - identifier: return.type - count: 1 - path: src/DatabaseInterface.php - - message: '#^Method PhpMyAdmin\\DatabaseInterface\:\:getColumnNames\(\) should return list\ but returns array\\.$#' identifier: return.type diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index e018c8f74b..d1bad97428 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -137,6 +137,9 @@ class DatabaseInterface implements DbalInterface private ListDatabase|null $databaseList = null; private readonly Config $config; + /** @var int|numeric-string */ + private static int|string $cachedAffectedRows = -1; + /** @param DbiExtension $extension Object to be used for database queries */ public function __construct(private DbiExtension $extension) { @@ -199,7 +202,7 @@ class DatabaseInterface implements DbalInterface } if ($cacheAffectedRows) { - $GLOBALS['cached_affected_rows'] = $this->affectedRows($connectionType, false); + self::$cachedAffectedRows = $this->affectedRows($connectionType, false); } if ($this->config->config->debug->sql) { @@ -1785,7 +1788,7 @@ class DatabaseInterface implements DbalInterface } if ($getFromCache) { - return $GLOBALS['cached_affected_rows']; + return self::$cachedAffectedRows; } return $this->extension->affectedRows($this->connections[$connectionType->value]); diff --git a/src/Server/Status/Monitor.php b/src/Server/Status/Monitor.php index f4935f1be3..7f7fe62055 100644 --- a/src/Server/Status/Monitor.php +++ b/src/Server/Status/Monitor.php @@ -485,8 +485,6 @@ class Monitor string $database, string $query, ): array { - $GLOBALS['cached_affected_rows'] ??= null; - $return = []; if ($database !== '') { @@ -503,7 +501,7 @@ class Monitor $sqlQuery = preg_replace('/^(\s*SELECT)/i', '\\1 SQL_NO_CACHE', $query); $this->dbi->tryQuery($sqlQuery); - $return['affectedRows'] = $GLOBALS['cached_affected_rows']; + $return['affectedRows'] = $this->dbi->affectedRows(); $result = $this->dbi->tryQuery('EXPLAIN ' . $sqlQuery); if ($result !== false) {