From c9c286b32a29e657e101f4917d6ff79b3bd96194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sun, 17 Mar 2024 14:37:39 -0300 Subject: [PATCH 1/2] Replace DBG config array access with Debug class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- phpstan-baseline.neon | 15 ----------- psalm-baseline.xml | 27 +++++++++++-------- src/Config/Validator.php | 3 ++- src/Console.php | 3 +-- src/Controllers/HomeController.php | 2 +- src/Controllers/Setup/MainController.php | 2 +- src/DatabaseInterface.php | 5 ++-- src/Footer.php | 8 +++--- src/Plugins/Auth/AuthenticationCookie.php | 2 +- src/TwoFactor.php | 3 ++- tests/unit/DatabaseInterfaceTest.php | 5 ++-- tests/unit/Dbal/DbiDummyTest.php | 1 - tests/unit/FooterTest.php | 4 ++- tests/unit/Replication/ReplicationGuiTest.php | 1 - tests/unit/Stubs/DbiDummy.php | 4 --- tests/unit/TransformationsTest.php | 1 - tests/unit/TwoFactorTest.php | 13 +++++---- 17 files changed, 41 insertions(+), 58 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 57c991754b..6aa34646d9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -16725,16 +16725,6 @@ parameters: count: 2 path: tests/unit/Tracking/TrackingTest.php - - - message: "#^Cannot access offset 'sql' on mixed\\.$#" - count: 1 - path: tests/unit/TransformationsTest.php - - - - message: "#^Property PhpMyAdmin\\\\Config\\:\\:\\$settings \\(array\\{PmaAbsoluteUri\\: string, AuthLog\\: string, AuthLogSuccess\\: bool, PmaNoRelation_DisableWarning\\: bool, SuhosinDisableWarning\\: bool, LoginCookieValidityDisableWarning\\: bool, ReservedWordDisableWarning\\: bool, TranslationWarningThreshold\\: int, \\.\\.\\.\\}\\) does not accept array\\{PmaAbsoluteUri\\: string, AuthLog\\: string, AuthLogSuccess\\: bool, PmaNoRelation_DisableWarning\\: bool, SuhosinDisableWarning\\: bool, LoginCookieValidityDisableWarning\\: bool, ReservedWordDisableWarning\\: bool, TranslationWarningThreshold\\: int, \\.\\.\\.\\}\\.$#" - count: 1 - path: tests/unit/TransformationsTest.php - - message: "#^Property PhpMyAdmin\\\\Config\\:\\:\\$settings \\(array\\{PmaAbsoluteUri\\: string, AuthLog\\: string, AuthLogSuccess\\: bool, PmaNoRelation_DisableWarning\\: bool, SuhosinDisableWarning\\: bool, LoginCookieValidityDisableWarning\\: bool, ReservedWordDisableWarning\\: bool, TranslationWarningThreshold\\: int, \\.\\.\\.\\}\\) does not accept array\\{ServerDefault\\: 1, ActionLinksMode\\: 'icons'\\}\\.$#" count: 1 @@ -16755,11 +16745,6 @@ parameters: count: 2 path: tests/unit/TwoFactorTest.php - - - message: "#^Property PhpMyAdmin\\\\Config\\:\\:\\$settings \\(array\\{PmaAbsoluteUri\\: string, AuthLog\\: string, AuthLogSuccess\\: bool, PmaNoRelation_DisableWarning\\: bool, SuhosinDisableWarning\\: bool, LoginCookieValidityDisableWarning\\: bool, ReservedWordDisableWarning\\: bool, TranslationWarningThreshold\\: int, \\.\\.\\.\\}\\) does not accept array\\{PmaAbsoluteUri\\: string, AuthLog\\: string, AuthLogSuccess\\: bool, PmaNoRelation_DisableWarning\\: bool, SuhosinDisableWarning\\: bool, LoginCookieValidityDisableWarning\\: bool, ReservedWordDisableWarning\\: bool, TranslationWarningThreshold\\: int, \\.\\.\\.\\}\\.$#" - count: 1 - path: tests/unit/TwoFactorTest.php - - message: "#^Class PhpMyAdmin\\\\Tests\\\\TypesByDatabaseVersionTest has an uninitialized property \\$object\\. Give it default value or assign it in the constructor\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 8ab41af3e5..546087716d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -13231,6 +13231,10 @@ + + config->DBG->sql]]> + config->DBG->sql]]> + @@ -13440,6 +13444,10 @@ + + config->DBG->sql]]> + config->DBG->sql]]> + @@ -14409,7 +14417,6 @@ settings]]> settings]]> settings]]> - settings]]> @@ -14562,11 +14569,6 @@ - - - - - result, 1, 0)]]> @@ -14699,7 +14701,6 @@ - settings]]> 1, 'ActionLinksMode' => 'icons']]]> @@ -14737,10 +14738,14 @@ - - settings]]> - settings]]> - + + config->DBG->simple2fa]]> + config->DBG->simple2fa]]> + config->DBG->simple2fa]]> + config->DBG->simple2fa]]> + config->DBG->simple2fa]]> + config->DBG->simple2fa]]> + config['settings']['secret']]]> config['settings']['secret']]]> diff --git a/src/Config/Validator.php b/src/Config/Validator.php index cd0fdf7a68..48759a985e 100644 --- a/src/Config/Validator.php +++ b/src/Config/Validator.php @@ -220,7 +220,8 @@ class Validator string $pass, string $errorKey = 'Server', ): bool|array { - if (Config::getInstance()->settings['DBG']['demo']) { + $config = Config::getInstance(); + if ($config->config->DBG->demo) { // Connection test disabled on the demo server! return true; } diff --git a/src/Console.php b/src/Console.php index 8f735f5f33..f62a6b65ed 100644 --- a/src/Console.php +++ b/src/Console.php @@ -111,13 +111,12 @@ class Console $bookmarkFeature = $this->relation->getRelationParameters()->bookmarkFeature; $sqlHistory = $this->relation->getHistory($this->config->selectedServer['user']); $bookmarkContent = $this->getBookmarkContent(); - $debug = isset($this->config->settings['DBG']) && $this->config->settings['DBG']['sql']; return $this->template->render('console/display', [ 'has_bookmark_feature' => $bookmarkFeature !== null, 'sql_history' => $sqlHistory, 'bookmark_content' => $bookmarkContent, - 'debug' => $debug, + 'debug' => $this->config->config->DBG->sql, ]); } } diff --git a/src/Controllers/HomeController.php b/src/Controllers/HomeController.php index 1f6e0608f2..069415fb0a 100644 --- a/src/Controllers/HomeController.php +++ b/src/Controllers/HomeController.php @@ -229,7 +229,7 @@ class HomeController extends AbstractController 'server' => Current::$server, 'sync_favorite_tables' => $syncFavoriteTables, 'has_server' => $hasServer, - 'is_demo' => $config->settings['DBG']['demo'], + 'is_demo' => $config->config->DBG->demo, 'has_server_selection' => $hasServerSelection ?? false, 'server_selection' => $serverSelection ?? '', 'has_change_password_link' => ($config->selectedServer['auth_type'] ?? '') !== 'config' diff --git a/src/Controllers/Setup/MainController.php b/src/Controllers/Setup/MainController.php index 4e4acd31f0..23511c5d75 100644 --- a/src/Controllers/Setup/MainController.php +++ b/src/Controllers/Setup/MainController.php @@ -33,7 +33,7 @@ final class MainController public function __invoke(ServerRequest $request): Response { $config = Config::getInstance(); - if (@file_exists(CONFIG_FILE) && ! $config->settings['DBG']['demo']) { + if (@file_exists(CONFIG_FILE) && ! $config->config->DBG->demo) { $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND); return $response->write($this->template->render('error/generic', [ diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index ef580b634e..5aa2b6b319 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -209,7 +209,6 @@ class DatabaseInterface implements DbalInterface int $options = self::QUERY_BUFFERED, bool $cacheAffectedRows = true, ): ResultInterface|false { - $debug = isset($this->config->settings['DBG']) && $this->config->settings['DBG']['sql']; if (! isset($this->connections[$connectionType->value])) { return false; } @@ -226,7 +225,7 @@ class DatabaseInterface implements DbalInterface $GLOBALS['cached_affected_rows'] = $this->affectedRows($connectionType, false); } - if ($debug) { + if ($this->config->config->DBG->sql) { $errorMessage = $this->getError($connectionType); Utilities::debugLogQueryIntoSession( $query, @@ -234,7 +233,7 @@ class DatabaseInterface implements DbalInterface $result, $this->lastQueryExecutionTime, ); - if ($this->config->settings['DBG']['sqllog']) { + if ($this->config->config->DBG->sqllog) { openlog('phpMyAdmin', LOG_NDELAY | LOG_PID, LOG_USER); syslog( diff --git a/src/Footer.php b/src/Footer.php index b18aa8a4c1..59ecdd68f2 100644 --- a/src/Footer.php +++ b/src/Footer.php @@ -101,9 +101,7 @@ class Footer public function getDebugMessage(): string { $retval = '\'false\''; - if ( - $this->config->settings['DBG']['sql'] && empty($_REQUEST['no_debug']) && ! empty($_SESSION['debug']) - ) { + if ($this->config->config->DBG->sql && empty($_REQUEST['no_debug']) && ! empty($_SESSION['debug'])) { // Remove recursions and iterators from $_SESSION['debug'] self::removeRecursion($_SESSION['debug']); @@ -241,7 +239,7 @@ class Footer $errorMessages = $this->getErrorMessages(); $scripts = $this->scripts->getDisplay(); - if ($this->config->settings['DBG']['demo']) { + if ($this->config->config->DBG->demo) { $gitRevisionInfo = $this->getGitRevisionInfo(); } @@ -254,7 +252,7 @@ class Footer 'self_url' => $url ?? null, 'error_messages' => $errorMessages ?? '', 'scripts' => $scripts ?? '', - 'is_demo' => $this->config->settings['DBG']['demo'], + 'is_demo' => $this->config->config->DBG->demo, 'git_revision_info' => $gitRevisionInfo ?? [], 'footer' => $footer ?? '', ]); diff --git a/src/Plugins/Auth/AuthenticationCookie.php b/src/Plugins/Auth/AuthenticationCookie.php index 1f95343763..44c5400132 100644 --- a/src/Plugins/Auth/AuthenticationCookie.php +++ b/src/Plugins/Auth/AuthenticationCookie.php @@ -161,7 +161,7 @@ class AuthenticationCookie extends AuthenticationPlugin $response->addHTML($this->template->render('login/form', [ 'login_header' => $loginHeader, - 'is_demo' => $config->settings['DBG']['demo'], + 'is_demo' => $config->config->DBG->demo, 'error_messages' => $errorMessages, 'available_languages' => $availableLanguages, 'is_session_expired' => $sessionExpired, diff --git a/src/TwoFactor.php b/src/TwoFactor.php index b167e04e4c..0b1218cc72 100644 --- a/src/TwoFactor.php +++ b/src/TwoFactor.php @@ -118,7 +118,8 @@ class TwoFactor public function getAvailableBackends(): array { $result = []; - if (Config::getInstance()->settings['DBG']['simple2fa']) { + $config = Config::getInstance(); + if ($config->config->DBG->simple2fa) { $result[] = 'simple'; } diff --git a/tests/unit/DatabaseInterfaceTest.php b/tests/unit/DatabaseInterfaceTest.php index 2044bbcbbc..a5a9b7c853 100644 --- a/tests/unit/DatabaseInterfaceTest.php +++ b/tests/unit/DatabaseInterfaceTest.php @@ -276,7 +276,6 @@ class DatabaseInterfaceTest extends AbstractTestCase $config = Config::getInstance(); $config->selectedServer['DisableIS'] = false; - $config->settings['DBG']['sql'] = false; self::assertSame( 'utf8_general_ci', @@ -300,8 +299,10 @@ class DatabaseInterfaceTest extends AbstractTestCase public function testGetServerCollation(): void { $dbi = $this->createDatabaseInterface(); - Config::getInstance()->settings['DBG']['sql'] = true; + $config = Config::getInstance(); + $config->config->DBG->sql = true; self::assertSame('utf8_general_ci', $dbi->getServerCollation()); + $config->config->DBG->sql = false; } /** diff --git a/tests/unit/Dbal/DbiDummyTest.php b/tests/unit/Dbal/DbiDummyTest.php index 0a94692ff0..ad0fcca7e2 100644 --- a/tests/unit/Dbal/DbiDummyTest.php +++ b/tests/unit/Dbal/DbiDummyTest.php @@ -31,7 +31,6 @@ class DbiDummyTest extends AbstractTestCase $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; $config = Config::getInstance(); - $config->settings['DBG']['sql'] = false; $config->settings['IconvExtraParams'] = ''; } diff --git a/tests/unit/FooterTest.php b/tests/unit/FooterTest.php index 665a2dd25a..7bd2c62553 100644 --- a/tests/unit/FooterTest.php +++ b/tests/unit/FooterTest.php @@ -68,7 +68,8 @@ class FooterTest extends AbstractTestCase #[Group('medium')] public function testGetDebugMessage(): void { - Config::getInstance()->settings['DBG']['sql'] = true; + $config = Config::getInstance(); + $config->config->DBG->sql = true; $_SESSION['debug']['queries'] = [ ['count' => 1, 'time' => 0.2, 'query' => 'SELECT * FROM `pma_bookmark` WHERE 1'], ['count' => 1, 'time' => 2.5, 'query' => 'SELECT * FROM `db` WHERE 1'], @@ -79,6 +80,7 @@ class FooterTest extends AbstractTestCase . '{"count":1,"time":2.5,"query":"SELECT * FROM `db` WHERE 1"}]}', $this->object->getDebugMessage(), ); + $config->config->DBG->sql = false; } /** diff --git a/tests/unit/Replication/ReplicationGuiTest.php b/tests/unit/Replication/ReplicationGuiTest.php index 7a5ab71736..8105bde276 100644 --- a/tests/unit/Replication/ReplicationGuiTest.php +++ b/tests/unit/Replication/ReplicationGuiTest.php @@ -44,7 +44,6 @@ class ReplicationGuiTest extends AbstractTestCase $config->settings['ShowSQL'] = true; $config->settings['TableNavigationLinksMode'] = 'icons'; $config->settings['LimitChars'] = 100; - $config->settings['DBG']['sql'] = false; $config->settings['ShowHint'] = true; Current::$table = 'table'; diff --git a/tests/unit/Stubs/DbiDummy.php b/tests/unit/Stubs/DbiDummy.php index 6343d0e808..35ff216e97 100644 --- a/tests/unit/Stubs/DbiDummy.php +++ b/tests/unit/Stubs/DbiDummy.php @@ -11,7 +11,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Stubs; -use PhpMyAdmin\Config; use PhpMyAdmin\Config\Settings\Server; use PhpMyAdmin\Dbal\Connection; use PhpMyAdmin\Dbal\DbiExtension; @@ -2256,8 +2255,5 @@ class DbiDummy implements DbiExtension ], ], ]; - - /* Some basic setup for dummy driver */ - Config::getInstance()->settings['DBG']['sql'] = false; } } diff --git a/tests/unit/TransformationsTest.php b/tests/unit/TransformationsTest.php index 3f2fe9520a..352c6b1b2b 100644 --- a/tests/unit/TransformationsTest.php +++ b/tests/unit/TransformationsTest.php @@ -41,7 +41,6 @@ class TransformationsTest extends AbstractTestCase $config->selectedServer['table_info'] = ''; $config->selectedServer['table_coords'] = ''; $config->selectedServer['column_info'] = 'column_info'; - $config->settings['DBG']['sql'] = false; $this->transformations = new Transformations(); } diff --git a/tests/unit/TwoFactorTest.php b/tests/unit/TwoFactorTest.php index f30d433ec5..159c7adc52 100644 --- a/tests/unit/TwoFactorTest.php +++ b/tests/unit/TwoFactorTest.php @@ -46,7 +46,6 @@ class TwoFactorTest extends AbstractTestCase Current::$table = 'table'; $config = Config::getInstance(); $config->selectedServer['DisableIS'] = false; - $config->settings['DBG'] = ['simple2fa' => false, 'sql' => false]; $config->settings['NaturalOrder'] = true; $this->initStorageConfigAndData(); } @@ -175,11 +174,11 @@ class TwoFactorTest extends AbstractTestCase { $request = new ServerRequest(self::createStub(ServerRequestInterface::class)); $config = Config::getInstance(); - $config->settings['DBG']['simple2fa'] = true; + $config->config->DBG->simple2fa = true; $object = $this->getTwoFactorAndLoadConfig('user', ['type' => 'db', 'backend' => 'simple']); $backend = $object->getBackend(); self::assertSame('simple', $backend::$id); - $config->settings['DBG']['simple2fa'] = false; + $config->config->DBG->simple2fa = false; unset($_POST['2fa_confirm']); self::assertFalse($object->check($request, true)); @@ -204,7 +203,7 @@ class TwoFactorTest extends AbstractTestCase { $request = new ServerRequest(self::createStub(ServerRequestInterface::class)); $config = Config::getInstance(); - $config->settings['DBG']['simple2fa'] = true; + $config->config->DBG->simple2fa = true; $object = $this->getTwoFactorAndLoadConfig('user', null); $this->dummyDbi->assertAllQueriesConsumed(); @@ -229,7 +228,7 @@ class TwoFactorTest extends AbstractTestCase $this->initStorageConfigAndData();// Needs a re-init - $config->settings['DBG']['simple2fa'] = false; + $config->config->DBG->simple2fa = false; $object = $this->getTwoFactorAndLoadConfig('user', null); self::assertFalse($object->configure($request, 'simple')); $this->dummyDbi->assertAllQueriesConsumed(); @@ -484,13 +483,13 @@ class TwoFactorTest extends AbstractTestCase public function testBackends(): void { $config = Config::getInstance(); - $config->settings['DBG']['simple2fa'] = true; + $config->config->DBG->simple2fa = true; $object = $this->getTwoFactorAndLoadConfig('user', null); $backends = $object->getAllBackends(); self::assertCount( count($object->getAvailable()) + 1, $backends, ); - $config->settings['DBG']['simple2fa'] = false; + $config->config->DBG->simple2fa = false; } } From 63ae297cf9272752af14ef3f95d8884f8a3c41f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sun, 17 Mar 2024 15:28:20 -0300 Subject: [PATCH 2/2] Rename Config\Settings::$DBG to $debug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- phpstan-baseline.neon | 5 ---- psalm-baseline.xml | 21 ++++++++-------- src/Config/Settings.php | 8 +++---- src/Config/Validator.php | 2 +- src/Console.php | 2 +- src/Controllers/HomeController.php | 2 +- src/Controllers/Setup/MainController.php | 2 +- src/DatabaseInterface.php | 4 ++-- src/Footer.php | 6 ++--- src/Plugins/Auth/AuthenticationCookie.php | 2 +- src/TwoFactor.php | 2 +- tests/unit/Config/SettingsTest.php | 29 ++++++++++++++++------- tests/unit/DatabaseInterfaceTest.php | 4 ++-- tests/unit/FooterTest.php | 4 ++-- tests/unit/TwoFactorTest.php | 12 +++++----- 15 files changed, 56 insertions(+), 49 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6aa34646d9..8b0025c873 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -15475,11 +15475,6 @@ parameters: count: 1 path: tests/unit/Config/SettingsTest.php - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpMyAdmin\\\\\\\\Config\\\\\\\\Settings\\\\\\\\Debug' and PhpMyAdmin\\\\Config\\\\Settings\\\\Debug will always evaluate to true\\.$#" - count: 1 - path: tests/unit/Config/SettingsTest.php - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpMyAdmin\\\\\\\\Config\\\\\\\\Settings\\\\\\\\Export' and PhpMyAdmin\\\\Config\\\\Settings\\\\Export will always evaluate to true\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 546087716d..a6a668696f 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -12245,6 +12245,7 @@ + @@ -13232,8 +13233,8 @@ - config->DBG->sql]]> - config->DBG->sql]]> + config->debug->sql]]> + config->debug->sql]]> @@ -13445,8 +13446,8 @@ - config->DBG->sql]]> - config->DBG->sql]]> + config->debug->sql]]> + config->debug->sql]]> @@ -14739,12 +14740,12 @@ - config->DBG->simple2fa]]> - config->DBG->simple2fa]]> - config->DBG->simple2fa]]> - config->DBG->simple2fa]]> - config->DBG->simple2fa]]> - config->DBG->simple2fa]]> + config->debug->simple2fa]]> + config->debug->simple2fa]]> + config->debug->simple2fa]]> + config->debug->simple2fa]]> + config->debug->simple2fa]]> + config->debug->simple2fa]]> config['settings']['secret']]]> diff --git a/src/Config/Settings.php b/src/Config/Settings.php index 8d7bf03b9c..cacca8779b 100644 --- a/src/Config/Settings.php +++ b/src/Config/Settings.php @@ -2507,7 +2507,7 @@ final class Settings * * @link https://docs.phpmyadmin.net/en/latest/config.html#cfg_DBG */ - public Debug $DBG; + public Debug $debug; /** * Sets the working environment @@ -2808,7 +2808,7 @@ final class Settings $this->SendErrorReports = $this->setSendErrorReports($settings); $this->ConsoleEnterExecutes = $this->setConsoleEnterExecutes($settings); $this->zeroConf = $this->setZeroConf($settings); - $this->DBG = $this->setDBG($settings); + $this->debug = $this->setDebug($settings); $this->environment = $this->setEnvironment($settings); $this->DefaultFunctions = $this->setDefaultFunctions($settings); $this->maxRowPlotLimit = $this->setMaxRowPlotLimit($settings); @@ -3006,7 +3006,7 @@ final class Settings 'SendErrorReports' => $this->SendErrorReports, 'ConsoleEnterExecutes' => $this->ConsoleEnterExecutes, 'ZeroConf' => $this->zeroConf, - 'DBG' => $this->DBG->asArray(), + 'DBG' => $this->debug->asArray(), 'environment' => $this->environment, 'DefaultFunctions' => $this->DefaultFunctions, 'maxRowPlotLimit' => $this->maxRowPlotLimit, @@ -5389,7 +5389,7 @@ final class Settings } /** @param array $settings */ - private function setDBG(array $settings): Debug + private function setDebug(array $settings): Debug { if (isset($settings['DBG']) && is_array($settings['DBG'])) { return new Debug($settings['DBG']); diff --git a/src/Config/Validator.php b/src/Config/Validator.php index 48759a985e..d3dca2780f 100644 --- a/src/Config/Validator.php +++ b/src/Config/Validator.php @@ -221,7 +221,7 @@ class Validator string $errorKey = 'Server', ): bool|array { $config = Config::getInstance(); - if ($config->config->DBG->demo) { + if ($config->config->debug->demo) { // Connection test disabled on the demo server! return true; } diff --git a/src/Console.php b/src/Console.php index f62a6b65ed..e5197c509f 100644 --- a/src/Console.php +++ b/src/Console.php @@ -116,7 +116,7 @@ class Console 'has_bookmark_feature' => $bookmarkFeature !== null, 'sql_history' => $sqlHistory, 'bookmark_content' => $bookmarkContent, - 'debug' => $this->config->config->DBG->sql, + 'debug' => $this->config->config->debug->sql, ]); } } diff --git a/src/Controllers/HomeController.php b/src/Controllers/HomeController.php index 069415fb0a..e8b30187c9 100644 --- a/src/Controllers/HomeController.php +++ b/src/Controllers/HomeController.php @@ -229,7 +229,7 @@ class HomeController extends AbstractController 'server' => Current::$server, 'sync_favorite_tables' => $syncFavoriteTables, 'has_server' => $hasServer, - 'is_demo' => $config->config->DBG->demo, + 'is_demo' => $config->config->debug->demo, 'has_server_selection' => $hasServerSelection ?? false, 'server_selection' => $serverSelection ?? '', 'has_change_password_link' => ($config->selectedServer['auth_type'] ?? '') !== 'config' diff --git a/src/Controllers/Setup/MainController.php b/src/Controllers/Setup/MainController.php index 23511c5d75..6b74caacef 100644 --- a/src/Controllers/Setup/MainController.php +++ b/src/Controllers/Setup/MainController.php @@ -33,7 +33,7 @@ final class MainController public function __invoke(ServerRequest $request): Response { $config = Config::getInstance(); - if (@file_exists(CONFIG_FILE) && ! $config->config->DBG->demo) { + if (@file_exists(CONFIG_FILE) && ! $config->config->debug->demo) { $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND); return $response->write($this->template->render('error/generic', [ diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index 5aa2b6b319..8fea9bec39 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -225,7 +225,7 @@ class DatabaseInterface implements DbalInterface $GLOBALS['cached_affected_rows'] = $this->affectedRows($connectionType, false); } - if ($this->config->config->DBG->sql) { + if ($this->config->config->debug->sql) { $errorMessage = $this->getError($connectionType); Utilities::debugLogQueryIntoSession( $query, @@ -233,7 +233,7 @@ class DatabaseInterface implements DbalInterface $result, $this->lastQueryExecutionTime, ); - if ($this->config->config->DBG->sqllog) { + if ($this->config->config->debug->sqllog) { openlog('phpMyAdmin', LOG_NDELAY | LOG_PID, LOG_USER); syslog( diff --git a/src/Footer.php b/src/Footer.php index 59ecdd68f2..46f3a240a4 100644 --- a/src/Footer.php +++ b/src/Footer.php @@ -101,7 +101,7 @@ class Footer public function getDebugMessage(): string { $retval = '\'false\''; - if ($this->config->config->DBG->sql && empty($_REQUEST['no_debug']) && ! empty($_SESSION['debug'])) { + if ($this->config->config->debug->sql && empty($_REQUEST['no_debug']) && ! empty($_SESSION['debug'])) { // Remove recursions and iterators from $_SESSION['debug'] self::removeRecursion($_SESSION['debug']); @@ -239,7 +239,7 @@ class Footer $errorMessages = $this->getErrorMessages(); $scripts = $this->scripts->getDisplay(); - if ($this->config->config->DBG->demo) { + if ($this->config->config->debug->demo) { $gitRevisionInfo = $this->getGitRevisionInfo(); } @@ -252,7 +252,7 @@ class Footer 'self_url' => $url ?? null, 'error_messages' => $errorMessages ?? '', 'scripts' => $scripts ?? '', - 'is_demo' => $this->config->config->DBG->demo, + 'is_demo' => $this->config->config->debug->demo, 'git_revision_info' => $gitRevisionInfo ?? [], 'footer' => $footer ?? '', ]); diff --git a/src/Plugins/Auth/AuthenticationCookie.php b/src/Plugins/Auth/AuthenticationCookie.php index 44c5400132..5756237b6d 100644 --- a/src/Plugins/Auth/AuthenticationCookie.php +++ b/src/Plugins/Auth/AuthenticationCookie.php @@ -161,7 +161,7 @@ class AuthenticationCookie extends AuthenticationPlugin $response->addHTML($this->template->render('login/form', [ 'login_header' => $loginHeader, - 'is_demo' => $config->config->DBG->demo, + 'is_demo' => $config->config->debug->demo, 'error_messages' => $errorMessages, 'available_languages' => $availableLanguages, 'is_session_expired' => $sessionExpired, diff --git a/src/TwoFactor.php b/src/TwoFactor.php index 0b1218cc72..2b77f92392 100644 --- a/src/TwoFactor.php +++ b/src/TwoFactor.php @@ -119,7 +119,7 @@ class TwoFactor { $result = []; $config = Config::getInstance(); - if ($config->config->DBG->simple2fa) { + if ($config->config->debug->simple2fa) { $result[] = 'simple'; } diff --git a/tests/unit/Config/SettingsTest.php b/tests/unit/Config/SettingsTest.php index 530b889ab4..654de351b7 100644 --- a/tests/unit/Config/SettingsTest.php +++ b/tests/unit/Config/SettingsTest.php @@ -226,7 +226,6 @@ class SettingsTest extends TestCase 'DisableMultiTableMaintenance' => false, 'SendErrorReports' => 'ask', 'ConsoleEnterExecutes' => false, - 'DBG' => null, 'environment' => 'production', 'DefaultFunctions' => [ 'FUNC_CHAR' => '', @@ -268,11 +267,6 @@ class SettingsTest extends TestCase continue; } - if ($key === 'DBG') { - self::assertInstanceOf(Debug::class, $settings->DBG); - continue; - } - if ($key === 'Export') { self::assertInstanceOf(Export::class, $settings->Export); continue; @@ -468,7 +462,6 @@ class SettingsTest extends TestCase ['DisableMultiTableMaintenance', null, false], ['SendErrorReports', null, 'ask'], ['ConsoleEnterExecutes', null, false], - ['DBG', null, null], ['environment', null, 'production'], ['DefaultFunctions', null, ['FUNC_CHAR' => '', 'FUNC_DATE' => '', 'FUNC_NUMBER' => '', 'FUNC_SPATIAL' => 'GeomFromText', 'FUNC_UUID' => 'UUID', 'first_timestamp' => 'NOW']], ['maxRowPlotLimit', null, 500], @@ -634,7 +627,6 @@ class SettingsTest extends TestCase ['DisableMultiTableMaintenance', true, true], ['SendErrorReports', 'never', 'never'], ['ConsoleEnterExecutes', true, true], - ['DBG', [], null], ['environment', 'development', 'development'], ['DefaultFunctions', ['key' => 'value', 'key2' => 'value2'], ['key' => 'value', 'key2' => 'value2']], ['maxRowPlotLimit', 1, 1], @@ -963,7 +955,6 @@ class SettingsTest extends TestCase ['TrustedProxies', 'invalid', []], ['LinkLengthLimit', 0, 1000], ['SendErrorReports', 'invalid', 'ask'], - ['DBG', 'invalid', null], ['environment', 'invalid', 'production'], ['DefaultFunctions', 'invalid', ['FUNC_CHAR' => '', 'FUNC_DATE' => '', 'FUNC_NUMBER' => '', 'FUNC_SPATIAL' => 'GeomFromText', 'FUNC_UUID' => 'UUID', 'first_timestamp' => 'NOW']], ['maxRowPlotLimit', 0, 500], @@ -1453,6 +1444,26 @@ class SettingsTest extends TestCase yield 'valid value with type coercion' => [0, false]; } + /** @param mixed[] $expected */ + #[DataProvider('valuesForDebugProvider')] + public function testDebug(mixed $actual, array $expected): void + { + $settings = new Settings(['DBG' => $actual]); + $settingsArray = $settings->asArray(); + $expectedDebug = new Debug($expected); + self::assertEquals($expectedDebug, $settings->debug); + self::assertSame($expectedDebug->asArray(), $settingsArray['DBG']); + } + + /** @return iterable */ + public static function valuesForDebugProvider(): iterable + { + yield 'null value' => [null, []]; + yield 'valid value' => [[], []]; + yield 'valid value 2' => [['demo' => true], ['demo' => true]]; + yield 'invalid value' => ['invalid', []]; + } + /** @param array{internal: int, human: string} $expected */ #[DataProvider('valuesForMysqlMinVersionProvider')] public function testMysqlMinVersion(mixed $actual, array $expected): void diff --git a/tests/unit/DatabaseInterfaceTest.php b/tests/unit/DatabaseInterfaceTest.php index a5a9b7c853..7833cda269 100644 --- a/tests/unit/DatabaseInterfaceTest.php +++ b/tests/unit/DatabaseInterfaceTest.php @@ -300,9 +300,9 @@ class DatabaseInterfaceTest extends AbstractTestCase { $dbi = $this->createDatabaseInterface(); $config = Config::getInstance(); - $config->config->DBG->sql = true; + $config->config->debug->sql = true; self::assertSame('utf8_general_ci', $dbi->getServerCollation()); - $config->config->DBG->sql = false; + $config->config->debug->sql = false; } /** diff --git a/tests/unit/FooterTest.php b/tests/unit/FooterTest.php index 7bd2c62553..beffc7b3ba 100644 --- a/tests/unit/FooterTest.php +++ b/tests/unit/FooterTest.php @@ -69,7 +69,7 @@ class FooterTest extends AbstractTestCase public function testGetDebugMessage(): void { $config = Config::getInstance(); - $config->config->DBG->sql = true; + $config->config->debug->sql = true; $_SESSION['debug']['queries'] = [ ['count' => 1, 'time' => 0.2, 'query' => 'SELECT * FROM `pma_bookmark` WHERE 1'], ['count' => 1, 'time' => 2.5, 'query' => 'SELECT * FROM `db` WHERE 1'], @@ -80,7 +80,7 @@ class FooterTest extends AbstractTestCase . '{"count":1,"time":2.5,"query":"SELECT * FROM `db` WHERE 1"}]}', $this->object->getDebugMessage(), ); - $config->config->DBG->sql = false; + $config->config->debug->sql = false; } /** diff --git a/tests/unit/TwoFactorTest.php b/tests/unit/TwoFactorTest.php index 159c7adc52..69375876c1 100644 --- a/tests/unit/TwoFactorTest.php +++ b/tests/unit/TwoFactorTest.php @@ -174,11 +174,11 @@ class TwoFactorTest extends AbstractTestCase { $request = new ServerRequest(self::createStub(ServerRequestInterface::class)); $config = Config::getInstance(); - $config->config->DBG->simple2fa = true; + $config->config->debug->simple2fa = true; $object = $this->getTwoFactorAndLoadConfig('user', ['type' => 'db', 'backend' => 'simple']); $backend = $object->getBackend(); self::assertSame('simple', $backend::$id); - $config->config->DBG->simple2fa = false; + $config->config->debug->simple2fa = false; unset($_POST['2fa_confirm']); self::assertFalse($object->check($request, true)); @@ -203,7 +203,7 @@ class TwoFactorTest extends AbstractTestCase { $request = new ServerRequest(self::createStub(ServerRequestInterface::class)); $config = Config::getInstance(); - $config->config->DBG->simple2fa = true; + $config->config->debug->simple2fa = true; $object = $this->getTwoFactorAndLoadConfig('user', null); $this->dummyDbi->assertAllQueriesConsumed(); @@ -228,7 +228,7 @@ class TwoFactorTest extends AbstractTestCase $this->initStorageConfigAndData();// Needs a re-init - $config->config->DBG->simple2fa = false; + $config->config->debug->simple2fa = false; $object = $this->getTwoFactorAndLoadConfig('user', null); self::assertFalse($object->configure($request, 'simple')); $this->dummyDbi->assertAllQueriesConsumed(); @@ -483,13 +483,13 @@ class TwoFactorTest extends AbstractTestCase public function testBackends(): void { $config = Config::getInstance(); - $config->config->DBG->simple2fa = true; + $config->config->debug->simple2fa = true; $object = $this->getTwoFactorAndLoadConfig('user', null); $backends = $object->getAllBackends(); self::assertCount( count($object->getAvailable()) + 1, $backends, ); - $config->config->DBG->simple2fa = false; + $config->config->debug->simple2fa = false; } }