diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c14457073e..05d33f2e1a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -10845,12 +10845,6 @@ parameters: count: 1 path: src/Plugins/Auth/AuthenticationConfig.php - - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' - identifier: notEqual.notAllowed - count: 2 - path: src/Plugins/Auth/AuthenticationConfig.php - - message: '#^Loose comparison via "\=\=" is not allowed\.$#' identifier: equal.notAllowed @@ -11034,12 +11028,6 @@ parameters: count: 4 path: src/Plugins/Auth/AuthenticationHttp.php - - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' - identifier: notEqual.notAllowed - count: 1 - path: src/Plugins/Auth/AuthenticationHttp.php - - message: '#^Only booleans are allowed in &&, string given on the left side\.$#' identifier: booleanAnd.leftNotBoolean @@ -11127,12 +11115,6 @@ parameters: count: 1 path: src/Plugins/Auth/AuthenticationSignon.php - - - message: '#^Binary operation "\." between ''\#'' and mixed results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: src/Plugins/AuthenticationPlugin.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: diff --git a/psalm.xml b/psalm.xml index e3c25a4c30..e264e62c16 100644 --- a/psalm.xml +++ b/psalm.xml @@ -43,7 +43,6 @@ charset: string, complete_query: string, compression: 'none'|'zip'|'gzip', - errno: int, file_handle: resource|null, from_cookie: bool, knjenc: string, diff --git a/src/ConfigStorage/Relation.php b/src/ConfigStorage/Relation.php index c7200ac646..49e3659345 100644 --- a/src/ConfigStorage/Relation.php +++ b/src/ConfigStorage/Relation.php @@ -1450,7 +1450,7 @@ class Relation Current::$message = Message::error($error); - if ($GLOBALS['errno'] === 1044) { + if (DatabaseInterface::$errorNumber === 1044) { Current::$message = Message::error(sprintf( __( 'You do not have necessary privileges to create a database named' diff --git a/src/Dbal/DatabaseInterface.php b/src/Dbal/DatabaseInterface.php index e95258ad84..38b66340ed 100644 --- a/src/Dbal/DatabaseInterface.php +++ b/src/Dbal/DatabaseInterface.php @@ -142,6 +142,8 @@ class DatabaseInterface /** @var int|numeric-string */ private static int|string $cachedAffectedRows = -1; + public static int|null $errorNumber = null; + /** @param DbiExtension $extension Object to be used for database queries */ private function __construct(private DbiExtension $extension, private readonly Config $config) { @@ -665,7 +667,7 @@ class DatabaseInterface $databases = $this->fetchResult($sql, 'SCHEMA_NAME', null, $connectionType); $mysqlError = $this->getError($connectionType); - if ($databases === [] && isset($GLOBALS['errno'])) { + if ($databases === [] && self::$errorNumber !== null) { Generator::mysqlDie($mysqlError, $sql); } diff --git a/src/Dbal/DbiMysqli.php b/src/Dbal/DbiMysqli.php index f7a8946167..3965544ca6 100644 --- a/src/Dbal/DbiMysqli.php +++ b/src/Dbal/DbiMysqli.php @@ -235,7 +235,7 @@ class DbiMysqli implements DbiExtension */ public function getError(Connection $connection): string { - $GLOBALS['errno'] = 0; + DatabaseInterface::$errorNumber = 0; /** @var mysqli $mysqli */ $mysqli = $connection->connection; @@ -249,7 +249,7 @@ class DbiMysqli implements DbiExtension // keep the error number for further check after // the call to getError() - $GLOBALS['errno'] = $errorNumber; + DatabaseInterface::$errorNumber = $errorNumber; return Utilities::formatError($errorNumber, $errorMessage); } diff --git a/src/Plugins/Auth/AuthenticationConfig.php b/src/Plugins/Auth/AuthenticationConfig.php index 5226e74cda..2c1f4aa8ef 100644 --- a/src/Plugins/Auth/AuthenticationConfig.php +++ b/src/Plugins/Auth/AuthenticationConfig.php @@ -111,9 +111,9 @@ class AuthenticationConfig extends AuthenticationPlugin '', ) , '

' , "\n"; } elseif ( - ! isset($GLOBALS['errno']) - || $GLOBALS['errno'] != 2002 - && $GLOBALS['errno'] != 2003 + DatabaseInterface::$errorNumber === null + || DatabaseInterface::$errorNumber !== 2002 + && DatabaseInterface::$errorNumber !== 2003 ) { // if we display the "Server not responding" error, do not confuse // users by telling them they have a settings problem diff --git a/src/Plugins/Auth/AuthenticationHttp.php b/src/Plugins/Auth/AuthenticationHttp.php index f1b6694058..87633011b7 100644 --- a/src/Plugins/Auth/AuthenticationHttp.php +++ b/src/Plugins/Auth/AuthenticationHttp.php @@ -177,7 +177,7 @@ class AuthenticationHttp extends AuthenticationPlugin $this->logFailure($failure); $error = DatabaseInterface::getInstance()->getError(); - if ($error && $GLOBALS['errno'] != 1045) { + if ($error && DatabaseInterface::$errorNumber !== 1045) { $responseRenderer = ResponseRenderer::getInstance(); $responseRenderer->addHTML($this->template->render('error/generic', [ 'lang' => Current::$lang, diff --git a/src/Plugins/AuthenticationPlugin.php b/src/Plugins/AuthenticationPlugin.php index 112362f25e..ae2b4cb4d3 100644 --- a/src/Plugins/AuthenticationPlugin.php +++ b/src/Plugins/AuthenticationPlugin.php @@ -170,8 +170,8 @@ abstract class AuthenticationPlugin return htmlspecialchars($dbiError); } - if (isset($GLOBALS['errno'])) { - return '#' . $GLOBALS['errno'] . ' ' . $failure->getMessage(); + if (DatabaseInterface::$errorNumber !== null) { + return '#' . DatabaseInterface::$errorNumber . ' ' . $failure->getMessage(); } } diff --git a/tests/unit/ConfigStorage/RelationTest.php b/tests/unit/ConfigStorage/RelationTest.php index 2233380422..3c06b5bf01 100644 --- a/tests/unit/ConfigStorage/RelationTest.php +++ b/tests/unit/ConfigStorage/RelationTest.php @@ -958,7 +958,7 @@ class RelationTest extends AbstractTestCase $dummyDbi->addErrorCode('MYSQL_ERROR'); $dummyDbi->addResult('CREATE DATABASE IF NOT EXISTS `phpmyadmin`', false); - $GLOBALS['errno'] = 1044;// ER_DBACCESS_DENIED_ERROR + DatabaseInterface::$errorNumber = 1044;// ER_DBACCESS_DENIED_ERROR self::assertFalse( $relation->createPmaDatabase('phpmyadmin'), @@ -986,7 +986,7 @@ class RelationTest extends AbstractTestCase $dummyDbi->addErrorCode('Too many connections'); $dummyDbi->addResult('CREATE DATABASE IF NOT EXISTS `pma_1040`', false); - $GLOBALS['errno'] = 1040; + DatabaseInterface::$errorNumber = 1040; self::assertFalse( $relation->createPmaDatabase('pma_1040'), diff --git a/tests/unit/Plugins/Auth/AuthenticationCookieTest.php b/tests/unit/Plugins/Auth/AuthenticationCookieTest.php index da09c030a1..cd0194d0a5 100644 --- a/tests/unit/Plugins/Auth/AuthenticationCookieTest.php +++ b/tests/unit/Plugins/Auth/AuthenticationCookieTest.php @@ -770,7 +770,7 @@ class AuthenticationCookieTest extends AbstractTestCase ->willReturn(''); DatabaseInterface::$instance = $dbi; - $GLOBALS['errno'] = 42; + DatabaseInterface::$errorNumber = 42; $responseStub = new ResponseRendererStub(); (new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, $responseStub); @@ -811,7 +811,7 @@ class AuthenticationCookieTest extends AbstractTestCase DatabaseInterface::$instance = $dbi; $_COOKIE['pmaAuth-2'] = 'pass'; - unset($GLOBALS['errno']); + DatabaseInterface::$errorNumber = null; $responseStub = new ResponseRendererStub(); (new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, $responseStub); diff --git a/tests/unit/Plugins/Auth/AuthenticationHttpTest.php b/tests/unit/Plugins/Auth/AuthenticationHttpTest.php index eb89c19003..7ed48e70d9 100644 --- a/tests/unit/Plugins/Auth/AuthenticationHttpTest.php +++ b/tests/unit/Plugins/Auth/AuthenticationHttpTest.php @@ -265,7 +265,7 @@ class AuthenticationHttpTest extends AbstractTestCase ->willReturn('error 123', 'error 321', ''); DatabaseInterface::$instance = $dbi; - $GLOBALS['errno'] = 31; + DatabaseInterface::$errorNumber = 31; (new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null); ResponseRenderer::getInstance()->setAjax(false); @@ -277,7 +277,7 @@ class AuthenticationHttpTest extends AbstractTestCase // case 2 $config->selectedServer['host'] = 'host'; - $GLOBALS['errno'] = 1045; + DatabaseInterface::$errorNumber = 1045; (new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null); ResponseRenderer::getInstance()->setAjax(false); @@ -290,7 +290,7 @@ class AuthenticationHttpTest extends AbstractTestCase ResponseRenderer::getInstance()->setAjax(false); // case 3 - $GLOBALS['errno'] = 1043; + DatabaseInterface::$errorNumber = 1043; $response = $this->object->showFailure(AuthenticationFailure::deniedByDatabaseServer()); $result = (string) $response->getBody(); self::assertStringContainsString('Wrong username/password. Access denied.', $result); diff --git a/tests/unit/Plugins/Auth/AuthenticationSignonTest.php b/tests/unit/Plugins/Auth/AuthenticationSignonTest.php index d330ce8439..dfec00c376 100644 --- a/tests/unit/Plugins/Auth/AuthenticationSignonTest.php +++ b/tests/unit/Plugins/Auth/AuthenticationSignonTest.php @@ -344,7 +344,7 @@ class AuthenticationSignonTest extends AbstractTestCase { Config::getInstance()->selectedServer['SignonSession'] = 'newSession'; $_COOKIE['newSession'] = '42'; - unset($GLOBALS['errno']); + DatabaseInterface::$errorNumber = null; $this->object = $this->getMockBuilder(AuthenticationSignon::class) ->disableOriginalConstructor()