Skip to content

Commit

Permalink
Remove ContainerBuilder::setParameter() calls
Browse files Browse the repository at this point in the history
These parameters are only written, but never used.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Nov 3, 2023
1 parent 550673b commit 1514117
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 84 deletions.
50 changes: 0 additions & 50 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4509,7 +4509,6 @@
</MixedReturnStatement>
<PossiblyInvalidArgument>
<code>$postKey</code>
<code>$postKey</code>
</PossiblyInvalidArgument>
<PossiblyInvalidArrayOffset>
<code>$path[$depth - 1]</code>
Expand Down
2 changes: 0 additions & 2 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,13 @@ 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)) {
continue;
}

$GLOBALS[$postKey] = $_POST[$postKey];
$container->setParameter($postKey, $GLOBALS[$postKey]);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/Http/Middleware/CurrentServerGlobalSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
1 change: 0 additions & 1 deletion src/Http/Middleware/DatabaseAndTableSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
1 change: 0 additions & 1 deletion src/Http/Middleware/SqlQueryGlobalSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ private function setSQLQueryGlobalFromRequest(ContainerInterface $container, Ser
}

$GLOBALS['sql_query'] = $sqlQuery;
$container->setParameter('sql_query', $sqlQuery);
}
}
12 changes: 2 additions & 10 deletions src/Http/Middleware/UrlParamsSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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');
Expand All @@ -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;
}
Expand Down
3 changes: 0 additions & 3 deletions test/classes/Controllers/Database/StructureControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 0 additions & 4 deletions test/classes/Controllers/Sql/EnumValuesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions test/classes/Controllers/Sql/SetValuesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions test/classes/Controllers/Table/OperationsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']],
Expand Down
3 changes: 0 additions & 3 deletions test/classes/Controllers/Table/SearchControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 1514117

Please sign in to comment.