diff options
author | MaurĂcio Meneghini Fauth <mauricio@fauth.dev> | 2022-11-09 04:18:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-09 04:18:56 +0300 |
commit | 1c49ed0d18f82a1ff18731d5c3035d3462343981 (patch) | |
tree | c2890cdb98df7812838b831443b03ea59c0b0931 | |
parent | c2495d726c13b33b9ef1181ef4340d0f7d91a3ce (diff) | |
parent | 656ddda704711e798cfffbdbe5644b07179af597 (diff) |
Merge pull request #17873 from kamil-tekiela/Remove-$params-3
Refactor BinlogController.php
-rw-r--r-- | libraries/classes/Controllers/Server/BinlogController.php | 22 | ||||
-rw-r--r-- | phpstan-baseline.neon | 15 | ||||
-rw-r--r-- | psalm-baseline.xml | 19 | ||||
-rw-r--r-- | test/classes/Controllers/Server/BinlogControllerTest.php | 9 |
4 files changed, 36 insertions, 29 deletions
diff --git a/libraries/classes/Controllers/Server/BinlogController.php b/libraries/classes/Controllers/Server/BinlogController.php index 598c1087e1..2b69bbd8a7 100644 --- a/libraries/classes/Controllers/Server/BinlogController.php +++ b/libraries/classes/Controllers/Server/BinlogController.php @@ -44,33 +44,27 @@ class BinlogController extends AbstractController public function __invoke(ServerRequest $request): void { - $GLOBALS['errorUrl'] = $GLOBALS['errorUrl'] ?? null; + $log = $request->getParsedBodyParam('log'); + $position = (int) $request->getParsedBodyParam('pos', 0); - $params = [ - 'log' => $_POST['log'] ?? null, - 'pos' => $_POST['pos'] ?? null, - 'is_full_query' => $_POST['is_full_query'] ?? null, - ]; $GLOBALS['errorUrl'] = Url::getFromRoute('/'); if ($this->dbi->isSuperUser()) { $this->dbi->selectDb('mysql'); } - $position = ! empty($params['pos']) ? (int) $params['pos'] : 0; - $urlParams = []; - if (isset($params['log']) && array_key_exists($params['log'], $this->binaryLogs)) { - $urlParams['log'] = $params['log']; + if (array_key_exists($log, $this->binaryLogs)) { + $urlParams['log'] = $log; } $isFullQuery = false; - if (! empty($params['is_full_query'])) { + if ($request->hasBodyParam('is_full_query')) { $isFullQuery = true; $urlParams['is_full_query'] = 1; } - $sqlQuery = $this->getSqlQuery($params['log'] ?? '', $position, (int) $GLOBALS['cfg']['MaxRows']); + $sqlQuery = $this->getSqlQuery($log ?? '', $position, (int) $GLOBALS['cfg']['MaxRows']); $result = $this->dbi->query($sqlQuery); $numRows = $result->numRows(); @@ -99,7 +93,7 @@ class BinlogController extends AbstractController $this->render('server/binlog/index', [ 'url_params' => $urlParams, 'binary_logs' => $this->binaryLogs, - 'log' => $params['log'], + 'log' => $log, 'sql_message' => Generator::getMessage(Message::success(), $sqlQuery), 'values' => $values, 'has_previous' => $position > 0, @@ -123,7 +117,7 @@ class BinlogController extends AbstractController int $maxRows ): string { $sqlQuery = 'SHOW BINLOG EVENTS'; - if (! empty($log)) { + if ($log !== '') { $sqlQuery .= ' IN \'' . $log . '\''; } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 810b20150f..e93e3935d7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1396,6 +1396,21 @@ parameters: path: libraries/classes/Controllers/SchemaExportController.php - + message: "#^Cannot cast mixed to int\\.$#" + count: 1 + path: libraries/classes/Controllers/Server/BinlogController.php + + - + message: "#^Parameter \\#1 \\$key of function array_key_exists expects int\\|string, mixed given\\.$#" + count: 1 + path: libraries/classes/Controllers/Server/BinlogController.php + + - + message: "#^Parameter \\#1 \\$log of method PhpMyAdmin\\\\Controllers\\\\Server\\\\BinlogController\\:\\:getSqlQuery\\(\\) expects string, mixed given\\.$#" + count: 1 + path: libraries/classes/Controllers/Server/BinlogController.php + + - message: "#^Property PhpMyAdmin\\\\Controllers\\\\Server\\\\BinlogController\\:\\:\\$binaryLogs type has no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Controllers/Server/BinlogController.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index afaf9b619b..e95e287fca 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2583,22 +2583,17 @@ </MixedArgument> </file> <file src="libraries/classes/Controllers/Server/BinlogController.php"> - <MixedAssignment occurrences="1"> - <code>$GLOBALS['errorUrl']</code> + <MixedArgument occurrences="2"> + <code>$log</code> + <code>$log ?? ''</code> + </MixedArgument> + <MixedAssignment occurrences="2"> + <code>$log</code> + <code>$urlParams['log']</code> </MixedAssignment> - <PossiblyInvalidArgument occurrences="2"> - <code>$params['log']</code> - <code>$params['log'] ?? ''</code> - </PossiblyInvalidArgument> - <PossiblyInvalidCast occurrences="1"> - <code>$params['log'] ?? ''</code> - </PossiblyInvalidCast> <RedundantCast occurrences="1"> <code>(int) $GLOBALS['cfg']['MaxRows']</code> </RedundantCast> - <RiskyCast occurrences="1"> - <code>$params['pos']</code> - </RiskyCast> </file> <file src="libraries/classes/Controllers/Server/Databases/CreateController.php"> <MixedAssignment occurrences="1"> diff --git a/test/classes/Controllers/Server/BinlogControllerTest.php b/test/classes/Controllers/Server/BinlogControllerTest.php index abd9418a42..8b543e35c7 100644 --- a/test/classes/Controllers/Server/BinlogControllerTest.php +++ b/test/classes/Controllers/Server/BinlogControllerTest.php @@ -53,10 +53,13 @@ class BinlogControllerTest extends AbstractTestCase $controller = new BinlogController($response, new Template(), $GLOBALS['dbi']); - $_POST['log'] = 'index1'; - $_POST['pos'] = '3'; + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturnMap([ + ['log', null, 'index1'], + ['pos', 0, '3'], + ]); $this->dummyDbi->addSelectDb('mysql'); - $controller($this->createStub(ServerRequest::class)); + $controller($request); $this->dummyDbi->assertAllSelectsConsumed(); $actual = $response->getHTMLResult(); |