Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native param types #521

Merged
merged 3 commits into from
Jan 15, 2024
Merged
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
36 changes: 0 additions & 36 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -646,15 +646,6 @@
<code><![CDATA[self::STATEMENT_PARSERS[$statementName ?? $token->keyword]]]></code>
<code><![CDATA[self::STATEMENT_PARSERS[$token->keyword]]]></code>
</MixedArrayOffset>
<PossiblyNullArgument>
<code>$list</code>
<code>$list</code>
<code>$list</code>
<code><![CDATA[$token->token]]></code>
</PossiblyNullArgument>
<PossiblyNullArrayAccess>
<code><![CDATA[$list->tokens[$list->idx]]]></code>
</PossiblyNullArrayAccess>
<PossiblyNullArrayOffset>
<code><![CDATA[$list->tokens]]></code>
<code>self::STATEMENT_PARSERS</code>
@@ -664,27 +655,9 @@
<code><![CDATA[$list->idx]]></code>
<code>$prevLastIdx</code>
</PossiblyNullOperand>
<PossiblyNullPropertyAssignment>
<code>$list</code>
<code>$list</code>
</PossiblyNullPropertyAssignment>
<PossiblyNullPropertyAssignmentValue>
<code>$lastIdx</code>
</PossiblyNullPropertyAssignmentValue>
<PossiblyNullPropertyFetch>
<code><![CDATA[$list->count]]></code>
<code><![CDATA[$list->idx]]></code>
<code><![CDATA[$list->tokens]]></code>
<code><![CDATA[$token->keyword]]></code>
<code><![CDATA[$token->token]]></code>
<code><![CDATA[$token->type]]></code>
<code><![CDATA[$token->value]]></code>
</PossiblyNullPropertyFetch>
<PossiblyNullReference>
<code>getNextOfType</code>
<code>getNextOfType</code>
<code>getNextOfType</code>
</PossiblyNullReference>
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$list = &$this->list]]></code>
</UnsupportedPropertyReferenceUsage>
@@ -1053,8 +1026,6 @@
<code>$idx</code>
</MixedArgumentTypeCoercion>
<PossiblyFalseArgument>
<code>$params</code>
<code>$params</code>
<code><![CDATA[$params['c']]]></code>
<code><![CDATA[$params['q']]]></code>
<code><![CDATA[$params['q']]]></code>
@@ -1542,13 +1513,6 @@
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
</PossiblyNullArgument>
<PossiblyUnusedMethod>
<code>getFlagsProvider</code>
10 changes: 5 additions & 5 deletions src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
@@ -264,9 +264,9 @@
* @param Token[] $unknown unparsed tokens found at the end of operation
*/
public function __construct(
$options = null,
$field = null,
$partitions = null,
OptionsArray|null $options = null,
Expression|string|null $field = null,
array|null $partitions = null,
public array $unknown = []
) {
$this->partitions = $partitions;
@@ -328,12 +328,12 @@

// Skipping comments.
if ($token->type === TokenType::Comment) {
continue;

Check warning on line 331 in src/Components/AlterOperation.php

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "Continue_": --- Original +++ New @@ @@ } // Skipping comments. if ($token->type === TokenType::Comment) { - continue; + break; } // Skipping whitespaces. if ($token->type === TokenType::Whitespace) {
}

// Skipping whitespaces.
if ($token->type === TokenType::Whitespace) {
if ($state === 2) {

Check warning on line 336 in src/Components/AlterOperation.php

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ } // Skipping whitespaces. if ($token->type === TokenType::Whitespace) { - if ($state === 2) { + if ($state === 1) { // When parsing the unknown part, the whitespaces are // included to not break anything. $ret->unknown[] = $token;
// When parsing the unknown part, the whitespaces are
// included to not break anything.
$ret->unknown[] = $token;
@@ -347,7 +347,7 @@
// Not only when aliasing but also when parsing the body of an event, we just list the tokens of the
// body in the unknown tokens list, as they define their own statements.
if ($ret->options->has('AS') || $ret->options->has('DO')) {
for (; $list->idx < $list->count; ++$list->idx) {

Check warning on line 350 in src/Components/AlterOperation.php

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LessThan": --- Original +++ New @@ @@ // Not only when aliasing but also when parsing the body of an event, we just list the tokens of the // body in the unknown tokens list, as they define their own statements. if ($ret->options->has('AS') || $ret->options->has('DO')) { - for (; $list->idx < $list->count; ++$list->idx) { + for (; $list->idx <= $list->count; ++$list->idx) { if ($list->tokens[$list->idx]->type === TokenType::Delimiter) { break; }
if ($list->tokens[$list->idx]->type === TokenType::Delimiter) {
break;
}
@@ -387,7 +387,7 @@

$state = 2;
} elseif ($state === 2) {
if (is_string($token->value) || is_int($token->value)) {

Check warning on line 390 in src/Components/AlterOperation.php

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalOr": --- Original +++ New @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_int($token->value)) { + if (is_string($token->value) && is_int($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 390 in src/Components/AlterOperation.php

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalOrAllSubExprNegation": --- Original +++ New @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_int($token->value)) { + if (!is_string($token->value) || !is_int($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 390 in src/Components/AlterOperation.php

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalOrNegation": --- Original +++ New @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_int($token->value)) { + if (!(is_string($token->value) || is_int($token->value))) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 390 in src/Components/AlterOperation.php

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalOrSingleSubExprNegation": --- Original +++ New @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_int($token->value)) { + if (!is_string($token->value) || is_int($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 390 in src/Components/AlterOperation.php

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalOrSingleSubExprNegation": --- Original +++ New @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_int($token->value)) { + if (is_string($token->value) || !is_int($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;
$arrayKey = $token->value;
} else {
$arrayKey = $token->token;
@@ -406,10 +406,10 @@
$list->idx++; // Ignore the current token
$nextToken = $list->getNext();

if ($token->value === 'SET' && $nextToken !== null && $nextToken->value === '(') {

Check warning on line 409 in src/Components/AlterOperation.php

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ $list->idx++; // Ignore the current token $nextToken = $list->getNext(); - if ($token->value === 'SET' && $nextToken !== null && $nextToken->value === '(') { + if (($token->value === 'SET' || $nextToken !== null) && $nextToken->value === '(') { // To avoid adding the tokens between the SET() parentheses to the unknown tokens $list->getNextOfTypeAndValue(TokenType::Operator, ')'); } elseif ($token->value === 'SET' && $nextToken !== null && $nextToken->value === 'DEFAULT') {
// To avoid adding the tokens between the SET() parentheses to the unknown tokens
$list->getNextOfTypeAndValue(TokenType::Operator, ')');
} elseif ($token->value === 'SET' && $nextToken !== null && $nextToken->value === 'DEFAULT') {

Check warning on line 412 in src/Components/AlterOperation.php

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ if ($token->value === 'SET' && $nextToken !== null && $nextToken->value === '(') { // To avoid adding the tokens between the SET() parentheses to the unknown tokens $list->getNextOfTypeAndValue(TokenType::Operator, ')'); - } elseif ($token->value === 'SET' && $nextToken !== null && $nextToken->value === 'DEFAULT') { + } elseif (($token->value === 'SET' || $nextToken !== null) && $nextToken->value === 'DEFAULT') { // to avoid adding the `DEFAULT` token to the unknown tokens. ++$list->idx; } else {
// to avoid adding the `DEFAULT` token to the unknown tokens.
++$list->idx;
} else {
@@ -527,7 +527,7 @@
*
* @param string $tokenValue Value of current token
*/
private static function checkIfColumnDefinitionKeyword($tokenValue): bool
private static function checkIfColumnDefinitionKeyword(string $tokenValue): bool
{
$commonOptions = [
'AUTO_INCREMENT',
@@ -551,7 +551,7 @@
*
* @param Token $token token to check
*/
private static function checkIfTokenQuotedSymbol($token): bool
private static function checkIfTokenQuotedSymbol(Token $token): bool
{
return $token->type === TokenType::Symbol && $token->flags === Token::FLAG_SYMBOL_BACKTICK;
}
2 changes: 1 addition & 1 deletion src/Components/Condition.php
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ final class Condition implements Component
/**
* @param string $expr the condition or the operator
*/
public function __construct($expr = null)
public function __construct(string|null $expr = null)
{
$this->expr = trim((string) $expr);
}
10 changes: 5 additions & 5 deletions src/Components/CreateDefinition.php
Original file line number Diff line number Diff line change
@@ -150,11 +150,11 @@ final class CreateDefinition implements Component
* @param Reference|null $references references
*/
public function __construct(
$name = null,
$options = null,
$type = null,
$isConstraint = false,
$references = null
string|null $name = null,
OptionsArray|null $options = null,
DataType|Key|null $type = null,
bool $isConstraint = false,
Reference|null $references = null
) {
$this->name = $name;
$this->options = $options;
4 changes: 2 additions & 2 deletions src/Components/DataType.php
Original file line number Diff line number Diff line change
@@ -78,9 +78,9 @@ final class DataType implements Component
* @param OptionsArray $options the options of this data type
*/
public function __construct(
$name = null,
string|null $name = null,
array $parameters = [],
$options = null
OptionsArray|null $options = null
) {
$this->name = $name;
$this->parameters = $parameters;
8 changes: 6 additions & 2 deletions src/Components/Expression.php
Original file line number Diff line number Diff line change
@@ -110,8 +110,12 @@ final class Expression implements Component
* @param string|null $column the name of the column
* @param string|null $alias the name of the alias
*/
public function __construct($database = null, $table = null, $column = null, $alias = null)
{
public function __construct(
string|null $database = null,
string|null $table = null,
string|null $column = null,
string|null $alias = null
) {
if (($column === null) && ($alias === null)) {
$this->expr = $database; // case 1
$this->alias = $table; // case 2
2 changes: 1 addition & 1 deletion src/Components/FunctionCall.php
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ final class FunctionCall implements Component
* @param string|null $name the name of the function to be called
* @param string[]|ArrayObj|null $parameters the parameters of this function
*/
public function __construct($name = null, $parameters = null)
public function __construct(string|null $name = null, array|ArrayObj|null $parameters = null)
{
$this->name = $name;
if (is_array($parameters)) {
2 changes: 1 addition & 1 deletion src/Components/GroupKeyword.php
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
final class GroupKeyword implements Component
{
/** @var 'ASC'|'DESC'|null */
public string|null $type = null;

Check failure on line 21 in src/Components/GroupKeyword.php

GitHub Actions / lint-docs

The hint on "type" at @var is invalid: "'ASC'|'DESC'|null" on "PhpMyAdmin\SqlParser\Components\GroupKeyword::$type"

/**
* The expression that is used for grouping.
@@ -30,7 +30,7 @@
/**
* @param Expression $expr the expression that we are sorting by
*/
public function __construct($expr = null)
public function __construct(Expression|null $expr = null)
{
$this->expr = $expr;
}
14 changes: 7 additions & 7 deletions src/Components/IntoKeyword.php
Original file line number Diff line number Diff line change
@@ -113,12 +113,12 @@ final class IntoKeyword implements Component
* @param bool|null $fieldsKeyword options for OPTIONS keyword
*/
public function __construct(
$type = null,
$dest = null,
$columns = null,
$values = null,
$fieldsOptions = null,
$fieldsKeyword = null
string|null $type = null,
string|Expression|null $dest = null,
array|null $columns = null,
array|null $values = null,
OptionsArray|null $fieldsOptions = null,
bool|null $fieldsKeyword = null
) {
$this->type = $type;
$this->dest = $dest;
@@ -236,7 +236,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
* @param TokensList $list A token list
* @param string $keyword The keyword
*/
public function parseFileOptions(Parser $parser, TokensList $list, $keyword = 'FIELDS'): void
public function parseFileOptions(Parser $parser, TokensList $list, string $keyword = 'FIELDS'): void
{
++$list->idx;

8 changes: 6 additions & 2 deletions src/Components/JoinKeyword.php
Original file line number Diff line number Diff line change
@@ -78,8 +78,12 @@ final class JoinKeyword implements Component
* @param Condition[] $on join conditions
* @param ArrayObj $using columns joined
*/
public function __construct($type = null, $expr = null, $on = null, $using = null)
{
public function __construct(
string|null $type = null,
Expression|null $expr = null,
array|null $on = null,
ArrayObj|null $using = null
) {
$this->type = $type;
$this->expr = $expr;
$this->on = $on;
6 changes: 3 additions & 3 deletions src/Components/Key.php
Original file line number Diff line number Diff line change
@@ -105,10 +105,10 @@ final class Key implements Component
* @phpstan-param array{name?: string, length?: int, order?: string}[] $columns
*/
public function __construct(
$name = null,
string|null $name = null,
array $columns = [],
$type = null,
$options = null
string|null $type = null,
OptionsArray|null $options = null
) {
$this->name = $name;
$this->columns = $columns;
2 changes: 1 addition & 1 deletion src/Components/Limit.php
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ final class Limit implements Component
* @param int|string $rowCount the row count
* @param int|string $offset the offset
*/
public function __construct($rowCount = 0, $offset = 0)
public function __construct(int|string $rowCount = 0, int|string $offset = 0)
{
$this->rowCount = $rowCount;
$this->offset = $offset;
4 changes: 2 additions & 2 deletions src/Components/OptionsArray.php
Original file line number Diff line number Diff line change
@@ -291,7 +291,7 @@ public function build(): string
* @param bool $getExpr Gets the expression instead of the value.
* The value is the processed form of the expression.
*/
public function has($key, $getExpr = false): mixed
public function has(string $key, bool $getExpr = false): mixed
{
foreach ($this->options as $option) {
if (is_array($option)) {
@@ -313,7 +313,7 @@ public function has($key, $getExpr = false): mixed
*
* @return bool whether the key was found and deleted or not
*/
public function remove($key): bool
public function remove(string $key): bool
{
foreach ($this->options as $idx => $option) {
if (is_array($option)) {
2 changes: 1 addition & 1 deletion src/Components/OrderKeyword.php
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ final class OrderKeyword implements Component
* @param Expression $expr the expression that we are sorting by
* @param string $type the sorting type
*/
public function __construct($expr = null, $type = 'ASC')
public function __construct(Expression|null $expr = null, string $type = 'ASC')
{
$this->expr = $expr;
$this->type = $type;
2 changes: 1 addition & 1 deletion src/Components/ParameterDefinition.php
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ final class ParameterDefinition implements Component
* @param string $inOut parameter's directional type (IN / OUT or None)
* @param DataType $type parameter's type
*/
public function __construct($name = null, $inOut = null, $type = null)
public function __construct(string|null $name = null, string|null $inOut = null, DataType|null $type = null)
{
$this->name = $name;
$this->inOut = $inOut;
2 changes: 1 addition & 1 deletion src/Components/Reference.php
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ final class Reference implements Component
* @param string[] $columns the columns referenced
* @param OptionsArray $options the options
*/
public function __construct($table = null, array $columns = [], $options = null)
public function __construct(Expression|null $table = null, array $columns = [], OptionsArray|null $options = null)
{
$this->table = $table;
$this->columns = $columns;
2 changes: 1 addition & 1 deletion src/Components/RenameOperation.php
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ final class RenameOperation implements Component
* @param Expression $old old expression
* @param Expression $new new expression containing new name
*/
public function __construct($old = null, $new = null)
public function __construct(Expression|null $old = null, Expression|null $new = null)
{
$this->old = $old;
$this->new = $new;
2 changes: 1 addition & 1 deletion src/Components/SetOperation.php
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ final class SetOperation implements Component
* @param string $column Field's name..
* @param string $value new value
*/
public function __construct($column = '', $value = '')
public function __construct(string $column = '', string $value = '')
{
$this->column = $column;
$this->value = $value;
4 changes: 1 addition & 3 deletions src/Context.php
Original file line number Diff line number Diff line change
@@ -604,10 +604,8 @@ public static function getMode(): int

/**
* Sets the SQL mode.
*
* @param int|string $mode
*/
public static function setMode($mode = self::SQL_MODE_NONE): void
public static function setMode(int|string $mode = self::SQL_MODE_NONE): void
{
if (is_int($mode)) {
static::$mode = $mode;
2 changes: 1 addition & 1 deletion src/Exceptions/LexerException.php
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ class LexerException extends Exception
* @param int $pos the position of the character
* @param int $code the code of this error
*/
public function __construct($msg = '', $ch = '', $pos = 0, $code = 0)
public function __construct(string $msg = '', string $ch = '', int $pos = 0, int $code = 0)
{
parent::__construct($msg, $code);
$this->ch = $ch;
2 changes: 1 addition & 1 deletion src/Exceptions/ParserException.php
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ class ParserException extends Exception
* @param Token $token the token that produced this exception
* @param int $code the code of this error
*/
public function __construct($msg = '', Token|null $token = null, $code = 0)
public function __construct(string $msg = '', Token|null $token = null, int $code = 0)
{
parent::__construct($msg, $code);
$this->token = $token;
8 changes: 4 additions & 4 deletions src/Lexer.php
Original file line number Diff line number Diff line change
@@ -127,7 +127,7 @@ class Lexer
* enabled or not
* @param string $delimiter the delimiter to be used
*/
public function __construct($str, $strict = false, $delimiter = null)
public function __construct(string|UtfString $str, bool $strict = false, string|null $delimiter = null)
{
if (Context::$keywords === []) {
Context::load();
@@ -158,7 +158,7 @@ public function __construct($str, $strict = false, $delimiter = null)
*
* @param string $delimiter the new delimiter
*/
public function setDelimiter($delimiter): void
public function setDelimiter(string $delimiter): void
{
$this->delimiter = $delimiter;
$this->delimiterLen = strlen($delimiter);
@@ -383,7 +383,7 @@ private function solveAmbiguityOnFunctionKeywords(): void
*
* @throws LexerException throws the exception, if strict mode is enabled.
*/
public function error($msg, $str = '', $pos = 0, $code = 0): void
public function error(string $msg, string $str = '', int $pos = 0, int $code = 0): void
{
$error = new LexerException(
Translator::gettext($msg),
@@ -873,7 +873,7 @@ public function parseNumber(): Token|null
*
* @throws LexerException
*/
public function parseString($quote = ''): Token|null
public function parseString(string $quote = ''): Token|null
{
$token = $this->str[$this->last];
$flags = Context::isString($token);
4 changes: 2 additions & 2 deletions src/Parser.php
Original file line number Diff line number Diff line change
@@ -377,7 +377,7 @@ class Parser
* @param string|UtfString|TokensList|null $list the list of tokens to be parsed
* @param bool $strict whether strict mode should be enabled or not
*/
public function __construct($list = null, $strict = false)
public function __construct(string|UtfString|TokensList|null $list = null, bool $strict = false)
{
if (Context::$keywords === []) {
Context::load();
@@ -634,7 +634,7 @@ public function parse(): void
*
* @throws ParserException throws the exception, if strict mode is enabled.
*/
public function error($msg, Token|null $token = null, $code = 0): void
public function error(string $msg, Token|null $token = null, int $code = 0): void
{
$error = new ParserException(
Translator::gettext($msg),
2 changes: 1 addition & 1 deletion src/Statement.php
Original file line number Diff line number Diff line change
@@ -465,7 +465,7 @@ public function __toString(): string
*
* @throws Exceptions\ParserException
*/
public function validateClauseOrder($parser, $list): bool
public function validateClauseOrder(Parser $parser, TokensList $list): bool
{
$clauses = array_flip(array_keys($this->getClauses()));

Loading