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

Make constants const #505

Merged
merged 2 commits into from
Sep 17, 2023
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
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,12 @@ parameters:
path: src/Statement.php

-
message: "#^Offset 'class' does not exist on array\\{class\\?\\: class\\-string\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>, field\\?\\: non\\-empty\\-string, options\\?\\: array\\<string, string\\>\\}\\.$#"
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
path: src/Statement.php

-
message: "#^Offset 'field' does not exist on array\\{class\\?\\: class\\-string\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>, field\\?\\: non\\-empty\\-string, options\\?\\: array\\<string, string\\>\\}\\.$#"
message: "#^Offset 'field' 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
path: src/Statement.php

Expand Down
104 changes: 23 additions & 81 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,46 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="src/Components/AlterOperation.php">
<InvalidPropertyAssignmentValue>
<code><![CDATA[[
'ON SCHEDULE' => 1,
'EVERY' => [
2,
'expr',
],
'AT' => [
2,
'expr',
],
'STARTS' => [
3,
'expr',
],
'ENDS' => [
4,
'expr',
],
'ON COMPLETION PRESERVE' => 5,
'ON COMPLETION NOT PRESERVE' => 5,
'RENAME' => 6,
'TO' => [
7,
'expr',
['parseField' => 'table'],
],
'ENABLE' => 8,
'DISABLE' => 8,
'DISABLE ON SLAVE' => 8,
'COMMENT' => [
9,
'var',
],
'DO' => 10,
]]]></code>
</InvalidPropertyAssignmentValue>
<PossiblyInvalidArgument>
<code>$arrayKey</code>
</PossiblyInvalidArgument>
<PossiblyNullPropertyAssignmentValue>
<code>$options</code>
</PossiblyNullPropertyAssignmentValue>
Expand Down Expand Up @@ -104,7 +64,7 @@
</file>
<file src="src/Components/Condition.php">
<MixedArrayOffset>
<code><![CDATA[static::$allowedKeywords[$token->value]]]></code>
<code><![CDATA[self::ALLOWED_KEYWORDS[$token->value]]]></code>
</MixedArrayOffset>
<PossiblyUnusedProperty>
<code>$isOperator</code>
Expand Down Expand Up @@ -137,13 +97,9 @@
<code><![CDATA[$options['breakOnParentheses']]]></code>
</InvalidArgument>
<MixedArrayOffset>
<code><![CDATA[Parser::$statementParsers[$token->keyword]]]></code>
<code><![CDATA[self::$allowedKeywords[$token->keyword]]]></code>
<code><![CDATA[Parser::STATEMENT_PARSERS[$token->keyword]]]></code>
<code><![CDATA[self::ALLOWED_KEYWORDS[$token->keyword]]]></code>
</MixedArrayOffset>
<MixedArrayTypeCoercion>
<code><![CDATA[Parser::$statementParsers[$token->keyword]]]></code>
<code><![CDATA[self::$allowedKeywords[$token->keyword]]]></code>
</MixedArrayTypeCoercion>
<MixedAssignment>
<code>$field</code>
<code><![CDATA[$options['field']]]></code>
Expand Down Expand Up @@ -241,15 +197,11 @@
<code><![CDATA['']]></code>
</DocblockTypeContradiction>
<MixedArrayOffset>
<code><![CDATA[static::$joins[$token->keyword]]]></code>
<code><![CDATA[static::$joins[$token->keyword]]]></code>
<code><![CDATA[self::JOINS[$token->keyword]]]></code>
<code><![CDATA[self::JOINS[$token->keyword]]]></code>
</MixedArrayOffset>
<MixedArrayTypeCoercion>
<code><![CDATA[static::$joins[$token->keyword]]]></code>
<code><![CDATA[static::$joins[$token->keyword]]]></code>
</MixedArrayTypeCoercion>
<PossiblyFalseOperand>
<code><![CDATA[array_search($c->type, static::$joins)]]></code>
<code><![CDATA[array_search($c->type, self::JOINS)]]></code>
</PossiblyFalseOperand>
<PossiblyInvalidPropertyAssignmentValue>
<code>ArrayObj::parse($parser, $list)</code>
Expand Down Expand Up @@ -712,13 +664,9 @@
<code><![CDATA[new $class($this, $this->list)]]></code>
</InvalidStringClass>
<MixedArrayOffset>
<code><![CDATA[static::$statementParsers[$statementName ?? $token->keyword]]]></code>
<code><![CDATA[static::$statementParsers[$token->keyword]]]></code>
<code><![CDATA[self::STATEMENT_PARSERS[$statementName ?? $token->keyword]]]></code>
<code><![CDATA[self::STATEMENT_PARSERS[$token->keyword]]]></code>
</MixedArrayOffset>
<MixedArrayTypeCoercion>
<code><![CDATA[static::$statementParsers[$statementName ?? $token->keyword]]]></code>
<code><![CDATA[static::$statementParsers[$token->keyword]]]></code>
</MixedArrayTypeCoercion>
<ParamNameMismatch>
<code>$msg</code>
</ParamNameMismatch>
Expand All @@ -733,7 +681,7 @@
</PossiblyNullArrayAccess>
<PossiblyNullArrayOffset>
<code><![CDATA[$list->tokens]]></code>
<code>static::$statementParsers</code>
<code>self::STATEMENT_PARSERS</code>
</PossiblyNullArrayOffset>
<PossiblyNullOperand>
<code><![CDATA[$list->idx]]></code>
Expand Down Expand Up @@ -773,17 +721,13 @@
<MixedArrayOffset>
<code><![CDATA[$parsedClauses[$token->value]]]></code>
<code><![CDATA[$parsedClauses[$token->value]]]></code>
<code><![CDATA[Parser::$keywordParsers[$token->value]]]></code>
<code>Parser::$keywordParsers[$tokenValue]</code>
<code><![CDATA[Parser::$statementParsers[$token->keyword]]]></code>
<code><![CDATA[Parser::$statementParsers[$token->value]]]></code>
<code><![CDATA[Parser::KEYWORD_PARSERS[$token->value]]]></code>
<code>Parser::KEYWORD_PARSERS[$tokenValue]</code>
<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>
<MixedArrayTypeCoercion>
<code>Parser::$keywordParsers[$tokenValue]</code>
<code><![CDATA[Parser::$statementParsers[$token->keyword]]]></code>
</MixedArrayTypeCoercion>
<MixedAssignment>
<code>$tokenValue</code>
</MixedAssignment>
Expand All @@ -794,10 +738,10 @@
<code><![CDATA[$this->$field->build()]]></code>
</MixedOperand>
<PossiblyUndefinedArrayOffset>
<code><![CDATA[Parser::$keywordParsers[$name]['class']]]></code>
<code><![CDATA[Parser::$keywordParsers[$name]['field']]]></code>
<code><![CDATA[Parser::$keywordParsers[$tokenValue]['class']]]></code>
<code><![CDATA[Parser::$keywordParsers[$tokenValue]['field']]]></code>
<code><![CDATA[Parser::KEYWORD_PARSERS[$name]['class']]]></code>
<code><![CDATA[Parser::KEYWORD_PARSERS[$name]['field']]]></code>
<code><![CDATA[Parser::KEYWORD_PARSERS[$tokenValue]['class']]]></code>
<code><![CDATA[Parser::KEYWORD_PARSERS[$tokenValue]['field']]]></code>
</PossiblyUndefinedArrayOffset>
<PossiblyUnusedReturnValue>
<code>bool</code>
Expand Down Expand Up @@ -1179,19 +1123,17 @@
<code><![CDATA[$format['type']]]></code>
</MixedArrayAccess>
<MixedArrayOffset>
<code><![CDATA[JoinKeyword::$joins[$list->tokens[$list->idx - 2]->value]]]></code>
<code><![CDATA[JoinKeyword::$joins[$list->tokens[$list->idx - 4]->value]]]></code>
<code><![CDATA[JoinKeyword::$joins[$list->tokens[$list->idx - 6]->value]]]></code>
<code><![CDATA[JoinKeyword::$joins[$prev->value]]]></code>
<code><![CDATA[Parser::$keywordParsers[$token->keyword]]]></code>
<code><![CDATA[Parser::$statementParsers[$token->keyword]]]></code>
<code><![CDATA[JoinKeyword::JOINS[$list->tokens[$list->idx - 2]->value]]]></code>
<code><![CDATA[JoinKeyword::JOINS[$list->tokens[$list->idx - 4]->value]]]></code>
<code><![CDATA[JoinKeyword::JOINS[$list->tokens[$list->idx - 6]->value]]]></code>
<code><![CDATA[JoinKeyword::JOINS[$prev->value]]]></code>
<code><![CDATA[Parser::KEYWORD_PARSERS[$token->keyword]]]></code>
<code><![CDATA[Parser::STATEMENT_PARSERS[$token->keyword]]]></code>
<code>self::$inlineClauses[$lastClause]</code>
<code>self::$inlineClauses[$lastClause]</code>
<code>self::$shortClauses[$lastClause]</code>
</MixedArrayOffset>
<MixedArrayTypeCoercion>
<code><![CDATA[Parser::$keywordParsers[$token->keyword]]]></code>
<code><![CDATA[Parser::$statementParsers[$token->keyword]]]></code>
<code>self::$inlineClauses[$lastClause]</code>
<code>self::$inlineClauses[$lastClause]</code>
<code>self::$shortClauses[$lastClause]</code>
Expand Down
31 changes: 8 additions & 23 deletions src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
{
/**
* All database options.
*
* @var array<string, int|array<int, int|string>>
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
*/
public static $databaseOptions = [
public const DATABASE_OPTIONS = [
'CHARACTER SET' => [
1,
'var',
Expand Down Expand Up @@ -59,11 +56,8 @@

/**
* All table options.
*
* @var array<string, int|array<int, int|string>>
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
*/
public static $tableOptions = [
public const TABLE_OPTIONS = [
'ENGINE' => [
1,
'var=',
Expand Down Expand Up @@ -151,11 +145,8 @@

/**
* All user options.
*
* @var array<string, int|array<int, int|string>>
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
*/
public static $userOptions = [
public const USER_OPTIONS = [
'ATTRIBUTE' => [
1,
'var',
Expand Down Expand Up @@ -202,19 +193,13 @@

/**
* All view options.
*
* @var array<string, int|array<int, int|string>>
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
*/
public static $viewOptions = ['AS' => 1];
public const VIEW_OPTIONS = ['AS' => 1];

/**
* All event options.
*
* @var array<string, int|array<int, int|string>>
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
*/
public static $eventOptions = [
public const EVENT_OPTIONS = [
'ON SCHEDULE' => 1,
'EVERY' => [
2,
Expand Down Expand Up @@ -349,12 +334,12 @@

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

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

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

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

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

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

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ } // Skipping whitespaces. if ($token->type === Token::TYPE_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;
Expand All @@ -368,7 +353,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 356 in src/Components/AlterOperation.php

View workflow job for this annotation

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 === Token::TYPE_DELIMITER) { break; }
if ($list->tokens[$list->idx]->type === Token::TYPE_DELIMITER) {
break;
}
Expand Down Expand Up @@ -408,7 +393,7 @@

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

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

View workflow job for this annotation

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 396 in src/Components/AlterOperation.php

View workflow job for this annotation

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 396 in src/Components/AlterOperation.php

View workflow job for this annotation

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 396 in src/Components/AlterOperation.php

View workflow job for this annotation

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 396 in src/Components/AlterOperation.php

View workflow job for this annotation

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;
Expand Down Expand Up @@ -441,7 +426,7 @@
);
break;
}
} elseif (! empty(Parser::$statementParsers[$arrayKey])) {
} elseif (! empty(Parser::STATEMENT_PARSERS[$arrayKey])) {
// We have reached the end of ALTER operation and suddenly found
// a start to new statement, but have not found a delimiter between them
$parser->error(
Expand All @@ -450,8 +435,8 @@
);
break;
} elseif (
(array_key_exists($arrayKey, self::$databaseOptions)
|| array_key_exists($arrayKey, self::$tableOptions))
(array_key_exists($arrayKey, self::DATABASE_OPTIONS)
|| array_key_exists($arrayKey, self::TABLE_OPTIONS))
&& ! self::checkIfColumnDefinitionKeyword($arrayKey)
) {
// This alter operation has finished, which means a comma
Expand All @@ -469,10 +454,10 @@
if (
($token->type === Token::TYPE_KEYWORD)
&& (($token->keyword === 'PARTITION BY')
|| ($token->keyword === 'PARTITION' && $nextToken && $nextToken->value !== '('))

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

View workflow job for this annotation

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->type === Token::TYPE_KEYWORD && ($token->keyword === 'PARTITION BY' || $token->keyword === 'PARTITION' && $nextToken && $nextToken->value !== '(')) { + if ($token->type === Token::TYPE_KEYWORD && ($token->keyword === 'PARTITION BY' || ($token->keyword === 'PARTITION' || $nextToken) && $nextToken->value !== '(')) { $partitionState = 1; } elseif ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'PARTITION') { $partitionState = 2;
) {
$partitionState = 1;
} elseif (($token->type === Token::TYPE_KEYWORD) && ($token->keyword === 'PARTITION')) {

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

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ $nextToken = $list->getNext(); if ($token->type === Token::TYPE_KEYWORD && ($token->keyword === 'PARTITION BY' || $token->keyword === 'PARTITION' && $nextToken && $nextToken->value !== '(')) { $partitionState = 1; - } elseif ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'PARTITION') { + } elseif ($token->type === Token::TYPE_KEYWORD || $token->keyword === 'PARTITION') { $partitionState = 2; } --$list->idx;
$partitionState = 2;
}

Expand Down
12 changes: 4 additions & 8 deletions src/Components/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ final class Condition implements Component
{
/**
* Logical operators that can be used to delimit expressions.
*
* @var string[]
*/
public static $delimiters = [
private const DELIMITERS = [
'&&',
'||',
'AND',
Expand All @@ -33,10 +31,8 @@ final class Condition implements Component

/**
* List of allowed reserved keywords in conditions.
*
* @var array<string, int>
*/
public static $allowedKeywords = [
private const ALLOWED_KEYWORDS = [
'ALL' => 1,
'AND' => 1,
'BETWEEN' => 1,
Expand Down Expand Up @@ -143,7 +139,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

// Conditions are delimited by logical operators.
if (in_array($token->value, static::$delimiters, true)) {
if (in_array($token->value, self::DELIMITERS, true)) {
if ($betweenBefore && ($token->value === 'AND')) {
// The syntax of keyword `BETWEEN` is hard-coded.
$betweenBefore = false;
Expand Down Expand Up @@ -174,7 +170,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$betweenBefore = true;
}

if (($brackets === 0) && empty(static::$allowedKeywords[$token->value])) {
if (($brackets === 0) && empty(self::ALLOWED_KEYWORDS[$token->value])) {
break;
}
}
Expand Down
11 changes: 2 additions & 9 deletions src/Components/CreateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@ final class CreateDefinition implements Component
{
/**
* All field options.
*
* @var array<string, bool|int|array<int, int|string|array<string, bool>>>
* @psalm-var array<string, (bool|positive-int|array{
* 0: positive-int,
* 1: ('var'|'var='|'expr'|'expr='),
* 2?: array<string, bool>
* })>
*/
public static $fieldOptions = [
private const FIELD_OPTIONS = [
// Tells the `OptionsArray` to not sort the options.
// See the note below.
'_UNSORTED' => true,
Expand Down Expand Up @@ -271,7 +264,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$expr->type = DataType::parse($parser, $list);
$state = 3;
} elseif ($state === 3) {
$expr->options = OptionsArray::parse($parser, $list, static::$fieldOptions);
$expr->options = OptionsArray::parse($parser, $list, self::FIELD_OPTIONS);
$state = 4;
} elseif ($state === 4) {
if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'REFERENCES') {
Expand Down
7 changes: 2 additions & 5 deletions src/Components/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ final class DataType implements Component
{
/**
* All data type options.
*
* @var array<string, int|array<int, int|string>>
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
*/
public static $dataTypeOptions = [
private const DATA_TYPE_OPTIONS = [
'BINARY' => 1,
'CHARACTER SET' => [
2,
Expand Down Expand Up @@ -137,7 +134,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$parameters->raw : $parameters->values;
}

$ret->options = OptionsArray::parse($parser, $list, static::$dataTypeOptions);
$ret->options = OptionsArray::parse($parser, $list, self::DATA_TYPE_OPTIONS);
++$list->idx;
break;
}
Expand Down
Loading
Loading