diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b38f1953..fa8ea0c1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f5e65d17..34d6b381 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -84,15 +84,9 @@ - - value]]]> - $isOperator - - value])]]> - @@ -122,7 +116,6 @@ keyword]]]> - keyword]]]> $field @@ -150,7 +143,6 @@ - keyword])]]> @@ -770,7 +762,6 @@ value])]]> - value])]]> value]]]> @@ -796,7 +787,6 @@ keyword]]]> value]]]> value]]]> - value]]]> $tokenValue @@ -1390,9 +1380,6 @@ - - statements[0])]]> - int @@ -1462,9 +1449,6 @@ - - empty($param[0]) - $options $options diff --git a/src/Components/Condition.php b/src/Components/Condition.php index cdb45598..c3ef05cc 100644 --- a/src/Components/Condition.php +++ b/src/Components/Condition.php @@ -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', ]; /** @@ -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; } } diff --git a/src/Components/Expression.php b/src/Components/Expression.php index aafd18db..38a7558d 100644 --- a/src/Components/Expression.php +++ b/src/Components/Expression.php @@ -14,6 +14,7 @@ use PhpMyAdmin\SqlParser\TokenType; use function implode; +use function in_array; use function rtrim; use function strlen; use function trim; @@ -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', ]; /** @@ -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. diff --git a/src/Statement.php b/src/Statement.php index 6db9d155..4aa069b2 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -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; @@ -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) { /** @@ -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; } diff --git a/src/Utils/Query.php b/src/Utils/Query.php index 0edbe002..6ad1daa2 100644 --- a/src/Utils/Query.php +++ b/src/Utils/Query.php @@ -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); } diff --git a/src/Utils/Routine.php b/src/Utils/Routine.php index 2d538b02..60f9bd07 100644 --- a/src/Utils/Routine.php +++ b/src/Utils/Routine.php @@ -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 [ '', '',