Skip to content

Commit 692f0a1

Browse files
Merge pull request #18971 from MauricioFauth/sql-parser-quick-update
Update sql-parser dependency
2 parents 5140bed + 6aa4bc2 commit 692f0a1

7 files changed

Lines changed: 56 additions & 92 deletions

File tree

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline.neon

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10205,51 +10205,6 @@ parameters:
1020510205
count: 2
1020610206
path: src/Operations.php
1020710207

10208-
-
10209-
message: "#^Cannot access offset 0 on mixed\\.$#"
10210-
count: 3
10211-
path: src/ParseAnalyze.php
10212-
10213-
-
10214-
message: "#^Cannot access offset 1 on mixed\\.$#"
10215-
count: 1
10216-
path: src/ParseAnalyze.php
10217-
10218-
-
10219-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
10220-
count: 2
10221-
path: src/ParseAnalyze.php
10222-
10223-
-
10224-
message: "#^Offset 'select_tables' does not exist on array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\}\\.$#"
10225-
count: 1
10226-
path: src/ParseAnalyze.php
10227-
10228-
-
10229-
message: "#^Offset 'select_tables' on array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} in empty\\(\\) does not exist\\.$#"
10230-
count: 1
10231-
path: src/ParseAnalyze.php
10232-
10233-
-
10234-
message: "#^Offset 'select_tables' on array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} in isset\\(\\) does not exist\\.$#"
10235-
count: 1
10236-
path: src/ParseAnalyze.php
10237-
10238-
-
10239-
message: "#^Offset 'select_tables' on array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} on left side of \\?\\? does not exist\\.$#"
10240-
count: 1
10241-
path: src/ParseAnalyze.php
10242-
10243-
-
10244-
message: "#^Parameter \\#1 \\$info of static method PhpMyAdmin\\\\StatementInfo\\:\\:fromArray\\(\\) expects array\\{distinct\\: bool, drop_database\\: bool, group\\: bool, having\\: bool, is_affected\\: bool, is_analyse\\: bool, is_count\\: bool, is_delete\\: bool, \\.\\.\\.\\}, array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} given\\.$#"
10245-
count: 1
10246-
path: src/ParseAnalyze.php
10247-
10248-
-
10249-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
10250-
count: 1
10251-
path: src/ParseAnalyze.php
10252-
1025310208
-
1025410209
message: "#^Cannot access offset 'Table' on mixed\\.$#"
1025510210
count: 4
@@ -14415,11 +14370,6 @@ parameters:
1441514370
count: 1
1441614371
path: src/Sql.php
1441714372

14418-
-
14419-
message: "#^Parameter \\#1 \\$info of static method PhpMyAdmin\\\\StatementInfo\\:\\:fromArray\\(\\) expects array\\{distinct\\: bool, drop_database\\: bool, group\\: bool, having\\: bool, is_affected\\: bool, is_analyse\\: bool, is_count\\: bool, is_delete\\: bool, \\.\\.\\.\\}, array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} given\\.$#"
14420-
count: 1
14421-
path: src/Sql.php
14422-
1442314373
-
1442414374
message: "#^Parameter \\#1 \\$rows of static method PhpMyAdmin\\\\Message\\:\\:getMessageForAffectedRows\\(\\) expects int, int\\|string given\\.$#"
1442514375
count: 2
@@ -16465,11 +16415,6 @@ parameters:
1646516415
count: 2
1646616416
path: tests/classes/Display/ResultsTest.php
1646716417

16468-
-
16469-
message: "#^Parameter \\#1 \\$info of static method PhpMyAdmin\\\\StatementInfo\\:\\:fromArray\\(\\) expects array\\{distinct\\: bool, drop_database\\: bool, group\\: bool, having\\: bool, is_affected\\: bool, is_analyse\\: bool, is_count\\: bool, is_delete\\: bool, \\.\\.\\.\\}, array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} given\\.$#"
16470-
count: 3
16471-
path: tests/classes/Display/ResultsTest.php
16472-
1647316418
-
1647416419
message: "#^Parameter \\#1 \\$string of function htmlspecialchars_decode expects string, mixed given\\.$#"
1647516420
count: 1

psalm-baseline.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7850,14 +7850,6 @@
78507850
<code><![CDATA['data']]></code>
78517851
</TypeDoesNotContainNull>
78527852
</file>
7853-
<file src="src/ParseAnalyze.php">
7854-
<ArgumentTypeCoercion>
7855-
<code>$info</code>
7856-
</ArgumentTypeCoercion>
7857-
<RiskyTruthyFalsyComparison>
7858-
<code><![CDATA[empty($info['select_tables'])]]></code>
7859-
</RiskyTruthyFalsyComparison>
7860-
</file>
78617853
<file src="src/Partitioning/Maintenance.php">
78627854
<MixedArrayAccess>
78637855
<code><![CDATA[$row['Table']]]></code>
@@ -11504,9 +11496,6 @@
1150411496
</MixedAssignment>
1150511497
</file>
1150611498
<file src="src/Sql.php">
11507-
<ArgumentTypeCoercion>
11508-
<code>Query::getAll($fullSqlQuery)</code>
11509-
</ArgumentTypeCoercion>
1151011499
<DeprecatedMethod>
1151111500
<code>Config::getInstance()</code>
1151211501
<code>Config::getInstance()</code>
@@ -14165,11 +14154,6 @@
1416514154
</PossiblyUnusedMethod>
1416614155
</file>
1416714156
<file src="tests/classes/Display/ResultsTest.php">
14168-
<ArgumentTypeCoercion>
14169-
<code>Query::getAll($query)</code>
14170-
<code>Query::getAll($query)</code>
14171-
<code><![CDATA[Query::getAll('SELECT * FROM pma')]]></code>
14172-
</ArgumentTypeCoercion>
1417314157
<DeprecatedMethod>
1417414158
<code>Config::getInstance()</code>
1417514159
<code>Config::getInstance()</code>

src/ParseAnalyze.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<?php
2-
/**
3-
* Parse and analyse a SQL query
4-
*/
52

63
declare(strict_types=1);
74

@@ -13,7 +10,7 @@
1310
use function strcasecmp;
1411

1512
/**
16-
* PhpMyAdmin\ParseAnalyze class
13+
* Parse and analyse a SQL query
1714
*/
1815
class ParseAnalyze
1916
{
@@ -38,12 +35,11 @@ public static function sqlQuery(string $sqlQuery, string $db): array
3835
// If the targeted table (and database) are different than the ones that is
3936
// currently browsed, edit `$db` and `$table` to match them so other elements
4037
// (page headers, links, navigation panel) can be updated properly.
41-
if (! empty($info['select_tables'])) {
38+
if ($info->selectTables !== []) {
4239
// Previous table and database name is stored to check if it changed.
4340
$previousDb = $db;
4441

45-
if (count($info['select_tables']) > 1) {
46-
42+
if (count($info->selectTables) > 1) {
4743
/**
4844
* @todo if there are more than one table name in the Select:
4945
* - do not extract the first table name
@@ -52,21 +48,21 @@ public static function sqlQuery(string $sqlQuery, string $db): array
5248
*/
5349
$table = '';
5450
} else {
55-
$table = $info['select_tables'][0][0] ?? '';
56-
if (isset($info['select_tables'][0][1])) {
57-
$db = $info['select_tables'][0][1];
51+
$table = $info->selectTables[0][0] ?? '';
52+
if (isset($info->selectTables[0][1])) {
53+
$db = $info->selectTables[0][1];
5854
}
5955
}
6056

6157
// There is no point checking if a reloading is required if we already decided
6258
// to reload. Also, no reload is required for AJAX requests.
6359
$response = ResponseRenderer::getInstance();
64-
if (empty($info['reload']) && ! $response->isAjax()) {
60+
if (! $info->flags->reload && ! $response->isAjax()) {
6561
// NOTE: Database names are case-insensitive.
66-
$info['reload'] = strcasecmp($db, $previousDb) !== 0;
62+
$info->flags->reload = strcasecmp($db, $previousDb) !== 0;
6763
}
6864
}
6965

70-
return [StatementInfo::fromArray($info), $db, $table];
66+
return [StatementInfo::fromStatementInfo($info), $db, $table];
7167
}
7268
}

src/Sql.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private function handleSortOrder(
100100
);
101101

102102
// TODO: Avoid reparsing the query.
103-
$statementInfo = StatementInfo::fromArray(Query::getAll($fullSqlQuery));
103+
$statementInfo = StatementInfo::fromStatementInfo(Query::getAll($fullSqlQuery));
104104
} else {
105105
// Store the remembered table into session.
106106
$tableObject->setUiProp(

src/StatementInfo.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpMyAdmin\SqlParser\Parser;
88
use PhpMyAdmin\SqlParser\Statement;
9+
use PhpMyAdmin\SqlParser\Utils\StatementInfo as SqlParserStatementInfo;
910

1011
/** @psalm-immutable */
1112
class StatementInfo
@@ -126,4 +127,42 @@ public static function fromArray(array $info): self
126127
$info['select_expr'] ?? [],
127128
);
128129
}
130+
131+
public static function fromStatementInfo(SqlParserStatementInfo $statementInfo): self
132+
{
133+
/** @psalm-suppress DeprecatedProperty */
134+
return new self(
135+
$statementInfo->flags->distinct,
136+
$statementInfo->flags->dropDatabase,
137+
$statementInfo->flags->group,
138+
$statementInfo->flags->having,
139+
$statementInfo->flags->isAffected,
140+
$statementInfo->flags->isAnalyse,
141+
$statementInfo->flags->isCount,
142+
$statementInfo->flags->isDelete,
143+
$statementInfo->flags->isExplain,
144+
$statementInfo->flags->isExport,
145+
$statementInfo->flags->isFunc,
146+
$statementInfo->flags->isGroup,
147+
$statementInfo->flags->isInsert,
148+
$statementInfo->flags->isMaint,
149+
$statementInfo->flags->isProcedure,
150+
$statementInfo->flags->isReplace,
151+
$statementInfo->flags->isSelect,
152+
$statementInfo->flags->isShow,
153+
$statementInfo->flags->isSubQuery,
154+
$statementInfo->flags->join,
155+
$statementInfo->flags->limit,
156+
$statementInfo->flags->offset,
157+
$statementInfo->flags->order,
158+
$statementInfo->flags->queryType?->value ?? false,
159+
$statementInfo->flags->reload,
160+
$statementInfo->flags->selectFrom,
161+
$statementInfo->flags->union,
162+
$statementInfo->parser,
163+
$statementInfo->statement,
164+
$statementInfo->selectTables,
165+
$statementInfo->selectExpressions,
166+
);
167+
}
129168
}

tests/classes/Display/ResultsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function testisSelect(): void
101101
$this->object,
102102
DisplayResults::class,
103103
'isSelect',
104-
[StatementInfo::fromArray(Query::getAll('SELECT * FROM pma'))],
104+
[StatementInfo::fromStatementInfo(Query::getAll('SELECT * FROM pma'))],
105105
),
106106
);
107107
}
@@ -321,7 +321,7 @@ public function testSetHighlightedColumnGlobalField(): void
321321
$this->object,
322322
DisplayResults::class,
323323
'setHighlightedColumnGlobalField',
324-
[StatementInfo::fromArray(Query::getAll($query))],
324+
[StatementInfo::fromStatementInfo(Query::getAll($query))],
325325
);
326326

327327
self::assertEquals([
@@ -712,7 +712,7 @@ public function testOutputTransformations(): void
712712
'disabled',
713713
false,
714714
$query,
715-
StatementInfo::fromArray(Query::getAll($query)),
715+
StatementInfo::fromStatementInfo(Query::getAll($query)),
716716
],
717717
);
718718

0 commit comments

Comments
 (0)