Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Tekiela <tekiela246@gmail.com>2022-11-07 00:48:39 +0300
committerKamil Tekiela <tekiela246@gmail.com>2022-11-08 14:59:05 +0300
commit656ddda704711e798cfffbdbe5644b07179af597 (patch)
tree646196b43ec3d660e5b966b8faeac24c36289769
parentf103bdc1e2b733f8b10243a9d1aa04ee0ec83b11 (diff)
Refactor BinlogController.php
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
-rw-r--r--libraries/classes/Controllers/Server/BinlogController.php22
-rw-r--r--phpstan-baseline.neon15
-rw-r--r--psalm-baseline.xml19
-rw-r--r--test/classes/Controllers/Server/BinlogControllerTest.php9
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();