From 1514117a4763b9e84d8c40ee56d323bf2ebcfc03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 3 Nov 2023 18:56:40 -0300 Subject: [PATCH] Remove ContainerBuilder::setParameter() calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These parameters are only written, but never used. Signed-off-by: MaurĂ­cio Meneghini Fauth --- phpstan-baseline.neon | 50 ------------------- psalm-baseline.xml | 1 - src/Core.php | 2 - .../Middleware/CurrentServerGlobalSetting.php | 2 - .../Middleware/DatabaseAndTableSetting.php | 1 - src/Http/Middleware/SqlQueryGlobalSetting.php | 1 - src/Http/Middleware/UrlParamsSetting.php | 12 +---- .../Database/StructureControllerTest.php | 3 -- .../Sql/EnumValuesControllerTest.php | 4 -- .../Sql/SetValuesControllerTest.php | 4 -- .../Table/OperationsControllerTest.php | 3 -- .../Table/SearchControllerTest.php | 3 -- 12 files changed, 2 insertions(+), 84 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c0a59cc2ac2..c970ab8825f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -8325,11 +8325,6 @@ parameters: count: 1 path: src/Core.php - - - message: "#^Parameter \\#1 \\$name of method Symfony\\\\Component\\\\DependencyInjection\\\\Container\\:\\:setParameter\\(\\) expects string, \\(int\\|string\\) given\\.$#" - count: 1 - path: src/Core.php - - message: "#^Parameter \\#1 \\$pattern of function preg_match expects string, mixed given\\.$#" count: 1 @@ -8355,11 +8350,6 @@ parameters: count: 1 path: src/Core.php - - - message: "#^Parameter \\#2 \\$value of method Symfony\\\\Component\\\\DependencyInjection\\\\Container\\:\\:setParameter\\(\\) expects array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null, mixed given\\.$#" - count: 1 - path: src/Core.php - - message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" count: 3 @@ -11260,21 +11250,11 @@ parameters: count: 1 path: src/Http/Middleware/CurrentServerGlobalSetting.php - - - message: "#^Parameter \\#2 \\$value of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\:\\:setParameter\\(\\) expects array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null, mixed given\\.$#" - count: 1 - path: src/Http/Middleware/CurrentServerGlobalSetting.php - - message: "#^Cannot access offset 'table' on mixed\\.$#" count: 1 path: src/Http/Middleware/DatabaseAndTableSetting.php - - - message: "#^Parameter \\#2 \\$value of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\:\\:setParameter\\(\\) expects array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null, mixed given\\.$#" - count: 1 - path: src/Http/Middleware/DatabaseAndTableSetting.php - - message: "#^Cannot cast mixed to string\\.$#" count: 1 @@ -11305,11 +11285,6 @@ parameters: count: 2 path: src/Http/Middleware/UrlParamsSetting.php - - - message: "#^Parameter \\#2 \\$value of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\:\\:setParameter\\(\\) expects array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null, mixed given\\.$#" - count: 3 - path: src/Http/Middleware/UrlParamsSetting.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 @@ -19840,11 +19815,6 @@ parameters: count: 1 path: test/classes/Controllers/Database/StructureControllerTest.php - - - message: "#^Cannot call method setParameter\\(\\) on mixed\\.$#" - count: 2 - path: test/classes/Controllers/Database/StructureControllerTest.php - - message: "#^Cannot use array destructuring on mixed\\.$#" count: 8 @@ -19950,31 +19920,16 @@ parameters: count: 2 path: test/classes/Controllers/Sql/EnumValuesControllerTest.php - - - message: "#^Cannot call method setParameter\\(\\) on mixed\\.$#" - count: 4 - path: test/classes/Controllers/Sql/EnumValuesControllerTest.php - - message: "#^Cannot call method get\\(\\) on mixed\\.$#" count: 2 path: test/classes/Controllers/Sql/SetValuesControllerTest.php - - - message: "#^Cannot call method setParameter\\(\\) on mixed\\.$#" - count: 4 - path: test/classes/Controllers/Sql/SetValuesControllerTest.php - - message: "#^Cannot call method get\\(\\) on mixed\\.$#" count: 1 path: test/classes/Controllers/Table/OperationsControllerTest.php - - - message: "#^Cannot call method setParameter\\(\\) on mixed\\.$#" - count: 2 - path: test/classes/Controllers/Table/OperationsControllerTest.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 @@ -20020,11 +19975,6 @@ parameters: count: 1 path: test/classes/Controllers/Table/SearchControllerTest.php - - - message: "#^Cannot call method setParameter\\(\\) on mixed\\.$#" - count: 2 - path: test/classes/Controllers/Table/SearchControllerTest.php - - message: "#^Cannot call method willReturn\\(\\) on mixed\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 5d16b604a00..378dc455cc9 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -4509,7 +4509,6 @@ $postKey - $postKey $path[$depth - 1] diff --git a/src/Core.php b/src/Core.php index 27cd86a635a..253610a6741 100644 --- a/src/Core.php +++ b/src/Core.php @@ -560,7 +560,6 @@ static function ($item) use (&$empty): void { */ public static function setPostAsGlobal(array $postPatterns): void { - $container = self::getContainerBuilder(); foreach (array_keys($_POST) as $postKey) { foreach ($postPatterns as $onePostPattern) { if (! preg_match($onePostPattern, $postKey)) { @@ -568,7 +567,6 @@ public static function setPostAsGlobal(array $postPatterns): void } $GLOBALS[$postKey] = $_POST[$postKey]; - $container->setParameter($postKey, $GLOBALS[$postKey]); } } } diff --git a/src/Http/Middleware/CurrentServerGlobalSetting.php b/src/Http/Middleware/CurrentServerGlobalSetting.php index 6ef51bd129e..e52688cd0d9 100644 --- a/src/Http/Middleware/CurrentServerGlobalSetting.php +++ b/src/Http/Middleware/CurrentServerGlobalSetting.php @@ -38,7 +38,5 @@ private function setCurrentServerGlobal( $server = $config->selectServer($serverParamFromRequest); $GLOBALS['server'] = $server; $GLOBALS['urlParams']['server'] = $server; - $container->setParameter('server', $server); - $container->setParameter('url_params', $GLOBALS['urlParams']); } } diff --git a/src/Http/Middleware/DatabaseAndTableSetting.php b/src/Http/Middleware/DatabaseAndTableSetting.php index c68b2164121..a8d2b44cabc 100644 --- a/src/Http/Middleware/DatabaseAndTableSetting.php +++ b/src/Http/Middleware/DatabaseAndTableSetting.php @@ -44,6 +44,5 @@ private function setDatabaseAndTableFromRequest(ContainerInterface $container, S $GLOBALS['urlParams']['db'] = $GLOBALS['db']; $GLOBALS['urlParams']['table'] = $GLOBALS['table']; - $container->setParameter('url_params', $GLOBALS['urlParams']); } } diff --git a/src/Http/Middleware/SqlQueryGlobalSetting.php b/src/Http/Middleware/SqlQueryGlobalSetting.php index b98f717c52c..7528562c772 100644 --- a/src/Http/Middleware/SqlQueryGlobalSetting.php +++ b/src/Http/Middleware/SqlQueryGlobalSetting.php @@ -38,6 +38,5 @@ private function setSQLQueryGlobalFromRequest(ContainerInterface $container, Ser } $GLOBALS['sql_query'] = $sqlQuery; - $container->setParameter('sql_query', $sqlQuery); } } diff --git a/src/Http/Middleware/UrlParamsSetting.php b/src/Http/Middleware/UrlParamsSetting.php index ca7bf00bd3a..b456bac75ed 100644 --- a/src/Http/Middleware/UrlParamsSetting.php +++ b/src/Http/Middleware/UrlParamsSetting.php @@ -10,7 +10,6 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; final class UrlParamsSetting implements MiddlewareInterface { @@ -20,27 +19,21 @@ public function __construct(private readonly Config $config) public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $container = Core::getContainerBuilder(); - $GLOBALS['urlParams'] = []; - $container->setParameter('url_params', $GLOBALS['urlParams']); - $this->setGotoAndBackGlobals($container); + $this->setGotoAndBackGlobals(); return $handler->handle($request); } - private function setGotoAndBackGlobals(ContainerInterface $container): void + private function setGotoAndBackGlobals(): void { // Holds page that should be displayed. $GLOBALS['goto'] = ''; - $container->setParameter('goto', $GLOBALS['goto']); if (isset($_REQUEST['goto']) && Core::checkPageValidity($_REQUEST['goto'])) { $GLOBALS['goto'] = $_REQUEST['goto']; $GLOBALS['urlParams']['goto'] = $GLOBALS['goto']; - $container->setParameter('goto', $GLOBALS['goto']); - $container->setParameter('url_params', $GLOBALS['urlParams']); } else { if ($this->config->issetCookie('goto')) { $this->config->removeCookie('goto'); @@ -52,7 +45,6 @@ private function setGotoAndBackGlobals(ContainerInterface $container): void if (isset($_REQUEST['back']) && Core::checkPageValidity($_REQUEST['back'])) { // Returning page. $GLOBALS['back'] = $_REQUEST['back']; - $container->setParameter('back', $GLOBALS['back']); return; } diff --git a/test/classes/Controllers/Database/StructureControllerTest.php b/test/classes/Controllers/Database/StructureControllerTest.php index 70497f2f85a..6b03b39cae3 100644 --- a/test/classes/Controllers/Database/StructureControllerTest.php +++ b/test/classes/Controllers/Database/StructureControllerTest.php @@ -379,9 +379,6 @@ public function testGetValuesForMroongaTable(): void $GLOBALS['db'] = 'testdb'; $GLOBALS['table'] = 'mytable'; - $GLOBALS['containerBuilder']->setParameter('db', $GLOBALS['db']); - $GLOBALS['containerBuilder']->setParameter('table', $GLOBALS['table']); - /** @var StructureController $structureController */ $structureController = $GLOBALS['containerBuilder']->get(StructureController::class); diff --git a/test/classes/Controllers/Sql/EnumValuesControllerTest.php b/test/classes/Controllers/Sql/EnumValuesControllerTest.php index 80ff4f33113..1eaf3314f4e 100644 --- a/test/classes/Controllers/Sql/EnumValuesControllerTest.php +++ b/test/classes/Controllers/Sql/EnumValuesControllerTest.php @@ -52,8 +52,6 @@ public function testGetEnumValuesError(): void ['curr_value', null, 'b&c'], ]); - $GLOBALS['containerBuilder']->setParameter('db', $GLOBALS['db']); - $GLOBALS['containerBuilder']->setParameter('table', $GLOBALS['table']); /** @var EnumValuesController $sqlController */ $sqlController = $GLOBALS['containerBuilder']->get(EnumValuesController::class); $sqlController($request); @@ -95,8 +93,6 @@ public function testGetEnumValuesSuccess(): void ['curr_value', null, 'b&c'], ]); - $GLOBALS['containerBuilder']->setParameter('db', $GLOBALS['db']); - $GLOBALS['containerBuilder']->setParameter('table', $GLOBALS['table']); /** @var EnumValuesController $sqlController */ $sqlController = $GLOBALS['containerBuilder']->get(EnumValuesController::class); $sqlController($request); diff --git a/test/classes/Controllers/Sql/SetValuesControllerTest.php b/test/classes/Controllers/Sql/SetValuesControllerTest.php index 2d755d2d2f2..208f247942f 100644 --- a/test/classes/Controllers/Sql/SetValuesControllerTest.php +++ b/test/classes/Controllers/Sql/SetValuesControllerTest.php @@ -53,8 +53,6 @@ public function testError(): void $GLOBALS['db'] = 'cvv'; $GLOBALS['table'] = 'enums'; - $GLOBALS['containerBuilder']->setParameter('db', $GLOBALS['db']); - $GLOBALS['containerBuilder']->setParameter('table', $GLOBALS['table']); /** @var SetValuesController $sqlController */ $sqlController = $GLOBALS['containerBuilder']->get(SetValuesController::class); $sqlController($request); @@ -97,8 +95,6 @@ public function testSuccess(): void $GLOBALS['db'] = 'cvv'; $GLOBALS['table'] = 'enums'; - $GLOBALS['containerBuilder']->setParameter('db', $GLOBALS['db']); - $GLOBALS['containerBuilder']->setParameter('table', $GLOBALS['table']); /** @var SetValuesController $sqlController */ $sqlController = $GLOBALS['containerBuilder']->get(SetValuesController::class); $sqlController($request); diff --git a/test/classes/Controllers/Table/OperationsControllerTest.php b/test/classes/Controllers/Table/OperationsControllerTest.php index 7e3a1cc0fda..71bf9814919 100644 --- a/test/classes/Controllers/Table/OperationsControllerTest.php +++ b/test/classes/Controllers/Table/OperationsControllerTest.php @@ -47,9 +47,6 @@ public function testOperationsController(): void $this->loadDbiIntoContainerBuilder(); $this->loadResponseIntoContainerBuilder(); - $GLOBALS['containerBuilder']->setParameter('db', 'test_db'); - $GLOBALS['containerBuilder']->setParameter('table', 'test_table'); - $this->dummyDbi->addResult( 'SELECT `SCHEMA_NAME` FROM `INFORMATION_SCHEMA`.`SCHEMATA`', [['test_db']], diff --git a/test/classes/Controllers/Table/SearchControllerTest.php b/test/classes/Controllers/Table/SearchControllerTest.php index d6b99419cf5..820dc4b3a0f 100644 --- a/test/classes/Controllers/Table/SearchControllerTest.php +++ b/test/classes/Controllers/Table/SearchControllerTest.php @@ -153,9 +153,6 @@ public function testGetDataRowAction(): void ], ); - $GLOBALS['containerBuilder']->setParameter('db', 'PMA'); - $GLOBALS['containerBuilder']->setParameter('table', 'PMA_BookMark'); - /** @var SearchController $ctrl */ $ctrl = $GLOBALS['containerBuilder']->get(SearchController::class);