Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ parameters:
count: 1
path: src/Statement.php

-
message: "#^Cannot cast mixed to string\\.$#"
count: 1
path: src/Statement.php

-
message: "#^Offset 'class' does not exist on array\\{\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\Array2d', field\\: 'values'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\ArrayObj', field\\: 'partition'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\Condition', field\\: 'having'\\|'where'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\Expression', field\\: 'table', options\\: array\\{parseField\\: 'table'\\}\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\ExpressionArray', field\\: 'expr'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\ExpressionArray', field\\: 'fields'\\|'tables', options\\: array\\{parseField\\: 'table'\\}\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\ExpressionArray', field\\: 'from', options\\: array\\{field\\: 'table'\\}\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\FunctionCall', field\\: 'call'\\|'procedure'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\GroupKeyword', field\\: 'group'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\IndexHint', field\\: 'index_hints'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\IntoKeyword', field\\: 'into'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\JoinKeyword', field\\: 'join'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\Limit', field\\: 'limit'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\OptionsArray', field\\: 'endOptions'\\|'groupOptions'\\|'options'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\OrderKeyword', field\\: 'order'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\RenameOperation', field\\: 'renames'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\SetOperation', field\\: 'set'\\}\\|array\\{class\\: 'PhpMyAdmin\\\\\\\\SqlParser\\\\\\\\Components\\\\\\\\UnionKeyword', field\\: 'union'\\}\\.$#"
count: 1
Expand Down
16 changes: 0 additions & 16 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,9 @@
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Components/Condition.php">
<MixedArrayOffset>
<code><![CDATA[self::ALLOWED_KEYWORDS[$token->value]]]></code>
</MixedArrayOffset>
<PossiblyUnusedProperty>
<code>$isOperator</code>
</PossiblyUnusedProperty>
<TypeDoesNotContainType>
<code><![CDATA[empty(self::ALLOWED_KEYWORDS[$token->value])]]></code>
</TypeDoesNotContainType>
</file>
<file src="src/Components/CreateDefinition.php">
<MixedAssignment>
Expand Down Expand Up @@ -122,7 +116,6 @@
<file src="src/Components/Expression.php">
<MixedArrayOffset>
<code><![CDATA[Parser::STATEMENT_PARSERS[$token->keyword]]]></code>
<code><![CDATA[self::ALLOWED_KEYWORDS[$token->keyword]]]></code>
</MixedArrayOffset>
<MixedAssignment>
<code>$field</code>
Expand Down Expand Up @@ -150,7 +143,6 @@
</RiskyTruthyFalsyComparison>
<TypeDoesNotContainType>
<code><![CDATA[$brackets < 0]]></code>
<code><![CDATA[empty(self::ALLOWED_KEYWORDS[$token->keyword])]]></code>
</TypeDoesNotContainType>
</file>
<file src="src/Components/ExpressionArray.php">
Expand Down Expand Up @@ -770,7 +762,6 @@
<file src="src/Statement.php">
<DocblockTypeContradiction>
<code><![CDATA[empty(static::$clauses[$token->value])]]></code>
<code><![CDATA[empty(static::$statementOptions[$token->value])]]></code>
</DocblockTypeContradiction>
<InvalidArgument>
<code><![CDATA[$parsedClauses[$token->value]]]></code>
Expand All @@ -796,7 +787,6 @@
<code><![CDATA[Parser::STATEMENT_PARSERS[$token->keyword]]]></code>
<code><![CDATA[Parser::STATEMENT_PARSERS[$token->value]]]></code>
<code><![CDATA[static::$clauses[$token->value]]]></code>
<code><![CDATA[static::$statementOptions[$token->value]]]></code>
</MixedArrayOffset>
<MixedAssignment>
<code>$tokenValue</code>
Expand Down Expand Up @@ -1390,9 +1380,6 @@
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Utils/Query.php">
<DocblockTypeContradiction>
<code><![CDATA[empty($parser->statements[0])]]></code>
</DocblockTypeContradiction>
<InvalidNullableReturnType>
<code>int</code>
</InvalidNullableReturnType>
Expand Down Expand Up @@ -1462,9 +1449,6 @@
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Utils/Routine.php">
<DocblockTypeContradiction>
<code>empty($param[0])</code>
</DocblockTypeContradiction>
<MixedArgumentTypeCoercion>
<code>$options</code>
<code>$options</code>
Expand Down
42 changes: 21 additions & 21 deletions src/Components/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ final class Condition implements Component
* List of allowed reserved keywords in conditions.
*/
private const ALLOWED_KEYWORDS = [
'ALL' => 1,
'AND' => 1,
'BETWEEN' => 1,
'COLLATE' => 1,
'EXISTS' => 1,
'IF' => 1,
'IN' => 1,
'INTERVAL' => 1,
'IS' => 1,
'LIKE' => 1,
'MATCH' => 1,
'NOT IN' => 1,
'NOT NULL' => 1,
'NOT' => 1,
'NULL' => 1,
'OR' => 1,
'REGEXP' => 1,
'RLIKE' => 1,
'SOUNDS' => 1,
'XOR' => 1,
'ALL',
'AND',
'BETWEEN',
'COLLATE',
'EXISTS',
'IF',
'IN',
'INTERVAL',
'IS',
'LIKE',
'MATCH',
'NOT IN',
'NOT NULL',
'NOT',
'NULL',
'OR',
'REGEXP',
'RLIKE',
'SOUNDS',
'XOR',
];

/**
Expand Down Expand Up @@ -165,7 +165,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$betweenBefore = true;
}

if (($brackets === 0) && empty(self::ALLOWED_KEYWORDS[$token->value])) {
if ($brackets === 0 && ! in_array($token->value, self::ALLOWED_KEYWORDS, true)) {
break;
}
}
Expand Down
35 changes: 18 additions & 17 deletions src/Components/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpMyAdmin\SqlParser\TokenType;

use function implode;
use function in_array;
use function rtrim;
use function strlen;
use function trim;
Expand All @@ -29,22 +30,22 @@ final class Expression implements Component
* List of allowed reserved keywords in expressions.
*/
private const ALLOWED_KEYWORDS = [
'AND' => 1,
'AS' => 1,
'BETWEEN' => 1,
'CASE' => 1,
'DUAL' => 1,
'DIV' => 1,
'IS' => 1,
'MOD' => 1,
'NOT' => 1,
'NOT NULL' => 1,
'NULL' => 1,
'OR' => 1,
'OVER' => 1,
'REGEXP' => 1,
'RLIKE' => 1,
'XOR' => 1,
'AND',
'AS',
'BETWEEN',
'CASE',
'DUAL',
'DIV',
'IS',
'MOD',
'NOT',
'NOT NULL',
'NULL',
'OR',
'OVER',
'REGEXP',
'RLIKE',
'XOR',
];

/**
Expand Down Expand Up @@ -231,7 +232,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
) {
$isExpr = true;
} elseif (($token->flags & Token::FLAG_KEYWORD_RESERVED) && ($brackets === 0)) {
if (empty(self::ALLOWED_KEYWORDS[$token->keyword])) {
if (! in_array($token->keyword, self::ALLOWED_KEYWORDS, true)) {
// A reserved keyword that is not allowed in the
// expression was found so the expression must have
// ended and a new clause is starting.
Expand Down
5 changes: 3 additions & 2 deletions src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Stringable;

use function array_flip;
use function array_key_exists;
use function array_keys;
use function in_array;
use function is_array;
Expand Down Expand Up @@ -201,7 +202,7 @@ public function parse(Parser $parser, TokensList $list): void
* For statements that do not have any options this is set to `true` by
* default.
*/
$parsedOptions = empty(static::$statementOptions);
$parsedOptions = static::$statementOptions === [];

for (; $list->idx < $list->count; ++$list->idx) {
/**
Expand Down Expand Up @@ -326,7 +327,7 @@ public function parse(Parser $parser, TokensList $list): void
}

if (! $parsedOptions) {
if (empty(static::$statementOptions[$token->value])) {
if (! array_key_exists((string) $token->value, static::$statementOptions)) {
// Skipping keyword because if it is not a option.
++$list->idx;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public static function getAll(string $query): array
{
$parser = new Parser($query);

if (empty($parser->statements[0])) {
if ($parser->statements === []) {
return static::getFlags(null, true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Routine.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function getParameter(string $param): array
// A dummy parser is used for error reporting.
$param = ParameterDefinition::parse(new Parser(), $lexer->list);

if (empty($param[0])) {
if ($param === []) {
return [
'',
'',
Expand Down