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

Minor fixes #520

Merged
merged 12 commits into from
Jan 12, 2024
29 changes: 12 additions & 17 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ parameters:

-
message: "#^Cannot access offset 'expr' on mixed\\.$#"
count: 4
count: 2
path: src/Components/OptionsArray.php

-
Expand All @@ -237,12 +237,12 @@ parameters:

-
message: "#^Cannot access offset 1 on mixed\\.$#"
count: 6
count: 2
path: src/Components/OptionsArray.php

-
message: "#^Cannot access offset 2 on mixed\\.$#"
count: 2
count: 1
path: src/Components/OptionsArray.php

-
Expand Down Expand Up @@ -370,11 +370,6 @@ parameters:
count: 1
path: src/Context.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: src/Core.php

-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Exceptions\\\\ParserException\\:\\:\\$token \\(PhpMyAdmin\\\\SqlParser\\\\Token\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
count: 1
Expand All @@ -391,22 +386,22 @@ parameters:
path: src/Lexer.php

-
message: "#^Parameter \\#1 \\$msg \\(string\\) of method PhpMyAdmin\\\\SqlParser\\\\Lexer\\:\\:error\\(\\) should be compatible with parameter \\$error \\(Exception\\) of method PhpMyAdmin\\\\SqlParser\\\\Core\\:\\:error\\(\\)$#"
message: "#^Parameter \\#1 \\$token of class PhpMyAdmin\\\\SqlParser\\\\Token constructor expects string, null given\\.$#"
count: 1
path: src/Lexer.php

-
message: "#^Parameter \\#1 \\$token of class PhpMyAdmin\\\\SqlParser\\\\Token constructor expects string, null given\\.$#"
message: "#^Parameter \\#3 \\$flags of class PhpMyAdmin\\\\SqlParser\\\\Token constructor expects int, int\\|null given\\.$#"
count: 1
path: src/Lexer.php

-
message: "#^Parameter \\#3 \\$flags of class PhpMyAdmin\\\\SqlParser\\\\Token constructor expects int, int\\|null given\\.$#"
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Lexer\\:\\:\\$delimiter \\(string\\) does not accept null\\.$#"
count: 1
path: src/Lexer.php

-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Lexer\\:\\:\\$delimiter \\(string\\) does not accept null\\.$#"
message: "#^Strict comparison using \\=\\=\\= between non\\-empty\\-array\\<non\\-empty\\-string, int\\> and array\\{\\} will always evaluate to false\\.$#"
count: 1
path: src/Lexer.php

Expand All @@ -430,11 +425,6 @@ parameters:
count: 4
path: src/Parser.php

-
message: "#^Parameter \\#1 \\$msg \\(string\\) of method PhpMyAdmin\\\\SqlParser\\\\Parser\\:\\:error\\(\\) should be compatible with parameter \\$error \\(Exception\\) of method PhpMyAdmin\\\\SqlParser\\\\Core\\:\\:error\\(\\)$#"
count: 1
path: src/Parser.php

-
message: "#^Parameter \\#2 \\$list of method PhpMyAdmin\\\\SqlParser\\\\Statement\\:\\:validateClauseOrder\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\TokensList, PhpMyAdmin\\\\SqlParser\\\\TokensList\\|null given\\.$#"
count: 3
Expand All @@ -445,6 +435,11 @@ parameters:
count: 1
path: src/Parser.php

-
message: "#^Strict comparison using \\=\\=\\= between non\\-empty\\-array\\<non\\-empty\\-string, int\\> and array\\{\\} will always evaluate to false\\.$#"
count: 1
path: src/Parser.php

-
message: "#^Call to an undefined static method PhpMyAdmin\\\\SqlParser\\\\Component\\:\\:buildAll\\(\\)\\.$#"
count: 1
Expand Down
136 changes: 3 additions & 133 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19">
<file src="src/Components/AlterOperation.php">
<PossiblyNullPropertyAssignmentValue>
<code>$options</code>
Expand Down Expand Up @@ -93,9 +93,6 @@
<DocblockTypeContradiction>
<code>$prev[0] === null</code>
</DocblockTypeContradiction>
<InvalidArgument>
<code><![CDATA[$options['breakOnParentheses']]]></code>
</InvalidArgument>
<MixedArrayOffset>
<code><![CDATA[Parser::STATEMENT_PARSERS[$token->keyword]]]></code>
<code><![CDATA[self::ALLOWED_KEYWORDS[$token->keyword]]]></code>
Expand All @@ -120,9 +117,6 @@
<code>$prev[1] !== null</code>
<code><![CDATA[empty($ret->function) && ($prev[1] !== null)]]></code>
</RedundantConditionGivenDocblockType>
<TypeDoesNotContainType>
<code><![CDATA[empty($options['field'])]]></code>
</TypeDoesNotContainType>
</file>
<file src="src/Components/ExpressionArray.php">
<InvalidReturnStatement>
Expand Down Expand Up @@ -456,9 +450,6 @@
<MixedAssignment>
<code>self::$keywords</code>
</MixedAssignment>
<PossiblyUnusedMethod>
<code>getIdentifierQuote</code>
</PossiblyUnusedMethod>
</file>
<file src="src/Contexts/ContextMariaDb100000.php">
<UnusedClass>
Expand Down Expand Up @@ -570,12 +561,6 @@
<code>ContextMySql80100</code>
</UnusedClass>
</file>
<file src="src/Core.php">
<RedundantConditionGivenDocblockType>
<code>Context::$keywords !== []</code>
<code>Context::$keywords !== []</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Exceptions/ParserException.php">
<PossiblyNullPropertyAssignmentValue>
<code>$token</code>
Expand All @@ -595,9 +580,6 @@
<NullArgument>
<code>null</code>
</NullArgument>
<ParamNameMismatch>
<code>$msg</code>
</ParamNameMismatch>
<PossiblyNullArgument>
<code>$flags</code>
<code><![CDATA[$this->str[$this->last + 1]]]></code>
Expand Down Expand Up @@ -664,9 +646,6 @@
<code><![CDATA[self::STATEMENT_PARSERS[$statementName ?? $token->keyword]]]></code>
<code><![CDATA[self::STATEMENT_PARSERS[$token->keyword]]]></code>
</MixedArrayOffset>
<ParamNameMismatch>
<code>$msg</code>
</ParamNameMismatch>
<PossiblyNullArgument>
<code>$list</code>
<code>$list</code>
Expand Down Expand Up @@ -1013,16 +992,13 @@
</PossiblyNullArrayOffset>
</file>
<file src="src/Tools/ContextGenerator.php">
<PossiblyNullArgument>
<PossiblyInvalidArgument>
<code><![CDATA[$options['keywords']]]></code>
</PossiblyNullArgument>
</PossiblyInvalidArgument>
<RedundantCondition>
<code>++$i !== $count</code>
<code>++$i !== $count</code>
</RedundantCondition>
<UnnecessaryVarAnnotation>
<code>string</code>
</UnnecessaryVarAnnotation>
</file>
<file src="src/Tools/CustomJsonSerializer.php">
<MixedAssignment>
Expand Down Expand Up @@ -1220,9 +1196,6 @@
<code>has</code>
<code>has</code>
</PossiblyNullReference>
<RedundantCondition>
<code><![CDATA[$ret['select_tables'] === []]]></code>
</RedundantCondition>
</file>
<file src="src/Utils/Routine.php">
<MixedArgumentTypeCoercion>
Expand Down Expand Up @@ -1265,7 +1238,6 @@
<code>$ret</code>
<code>$ret</code>
<code>$ret</code>
<code>$ret</code>
</PossiblyNullArrayOffset>
<PossiblyNullReference>
<code>has</code>
Expand Down Expand Up @@ -1603,108 +1575,6 @@
<code><![CDATA[$parser->statements[0]]]></code>
<code><![CDATA[$parser->statements[0]]]></code>
</ArgumentTypeCoercion>
<InvalidReturnStatement>
<code><![CDATA[[
[
'CREATE USER test',
[],
],
[
'CREATE TABLE `address` (
`address_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`address` varchar(50) NOT NULL,
`address2` varchar(50) DEFAULT NULL,
`district` varchar(20) NOT NULL,
`city_id` smallint(5) unsigned NOT NULL,
`postal_code` varchar(10) DEFAULT NULL,
`phone` varchar(20) NOT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`address_id`),
KEY `idx_fk_city_id` (`city_id`),
CONSTRAINT `fk_address_city` FOREIGN KEY (`city_id`) REFERENCES `city` (`city_id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=606 DEFAULT CHARSET=utf8',
[
'address_id' => [
'type' => 'SMALLINT',
'timestamp_not_null' => false,
],
'address' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
],
'address2' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
'default_value' => 'NULL',
],
'district' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
],
'city_id' => [
'type' => 'SMALLINT',
'timestamp_not_null' => false,
],
'postal_code' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
'default_value' => 'NULL',
],
'phone' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
],
'last_update' => [
'type' => 'TIMESTAMP',
'timestamp_not_null' => true,
'default_value' => 'CURRENT_TIMESTAMP',
'default_current_timestamp' => true,
'on_update_current_timestamp' => true,
],
],
],
[
'CREATE TABLE table1 (
a INT NOT NULL,
b VARCHAR(32),
c INT AS (a mod 10) VIRTUAL,
d VARCHAR(5) AS (left(b,5)) PERSISTENT
)',
[
'a' => [
'type' => 'INT',
'timestamp_not_null' => false,
],
'b' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
],
'c' => [
'type' => 'INT',
'timestamp_not_null' => false,
'generated' => true,
'expr' => '(a mod 10)',
],
'd' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
'generated' => true,
'expr' => '(left(b,5))',
],
],
],
]]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[list<array{string, array<string, array{
* type: string,
* timestamp_not_null: bool,
* default_value?: string,
* default_current_timestamp?: bool,
* on_update_current_timestamp?: bool,
* expr?: string
* }>}>]]></code>
</InvalidReturnType>
<PossiblyUnusedMethod>
<code>getFieldsProvider</code>
<code>getForeignKeysProvider</code>
Expand Down
4 changes: 2 additions & 2 deletions src/Components/GroupKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
final class GroupKeyword implements Component
{
/** @var mixed */
public $type;
/** @var 'ASC'|'DESC'|null */
public string|null $type = null;

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

View workflow job for this annotation

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.
Expand Down Expand Up @@ -62,7 +62,7 @@
*/
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

Check warning on line 65 in src/Components/GroupKeyword.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LessThan": --- Original +++ New @@ @@ * @var int */ $state = 0; - for (; $list->idx < $list->count; ++$list->idx) { + for (; $list->idx <= $list->count; ++$list->idx) { /** * Token parsed at this moment. */
/**
* Token parsed at this moment.
*/
Expand All @@ -74,7 +74,7 @@
}

// Skipping whitespaces and comments.
if (($token->type === TokenType::Whitespace) || ($token->type === TokenType::Comment)) {

Check warning on line 77 in src/Components/GroupKeyword.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

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

Expand All @@ -87,7 +87,7 @@
&& (($token->keyword === 'ASC') || ($token->keyword === 'DESC'))
) {
$expr->type = $token->keyword;
} elseif (($token->type === TokenType::Operator) && ($token->value === ',')) {

Check warning on line 90 in src/Components/GroupKeyword.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ } elseif ($state === 1) { if ($token->type === TokenType::Keyword && ($token->keyword === 'ASC' || $token->keyword === 'DESC')) { $expr->type = $token->keyword; - } elseif ($token->type === TokenType::Operator && $token->value === ',') { + } elseif ($token->type === TokenType::Operator || $token->value === ',') { if (!empty($expr->expr)) { $ret[] = $expr; }
if (! empty($expr->expr)) {
$ret[] = $expr;
}
Expand Down
10 changes: 0 additions & 10 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@
{
// NOTES: Only non-alphanumeric ASCII characters may be separators.
// `~` is the last printable ASCII character.
return $string <= '~'

Check warning on line 513 in src/Context.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LessThanOrEqualTo": --- Original +++ New @@ @@ { // NOTES: Only non-alphanumeric ASCII characters may be separators. // `~` is the last printable ASCII character. - return $string <= '~' && $string !== '_' && $string !== '$' && ($string < '0' || $string > '9') && ($string < 'a' || $string > 'z') && ($string < 'A' || $string > 'Z'); + return $string < '~' && $string !== '_' && $string !== '$' && ($string < '0' || $string > '9') && ($string < 'a' || $string > 'z') && ($string < 'A' || $string > 'Z'); } /** * Loads the specified context.
&& $string !== '_'
&& $string !== '$'
&& ($string < '0' || $string > '9')
Expand Down Expand Up @@ -563,21 +563,21 @@
public static function loadClosest(string $context = ''): string|null
{
$length = strlen($context);
for ($i = $length; $i > 0;) {

Check warning on line 566 in src/Context.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "GreaterThan": --- Original +++ New @@ @@ public static function loadClosest(string $context = '') : string|null { $length = strlen($context); - for ($i = $length; $i > 0;) { + for ($i = $length; $i >= 0;) { /* Trying to load the new context */ if (static::load($context)) { return $context;
/* Trying to load the new context */
if (static::load($context)) {
return $context;
}

/* Replace last two non zero digits by zeroes */
do {

Check warning on line 573 in src/Context.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "DoWhile": --- Original +++ New @@ @@ if (!is_numeric($part)) { break 2; } - } while (intval($part) === 0 && $i > 0); + } while (false); $context = substr($context, 0, $i) . '00' . substr($context, $i + 2); } /* Fallback to loading at least matching engine */
$i -= 2;

Check warning on line 574 in src/Context.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ } /* Replace last two non zero digits by zeroes */ do { - $i -= 2; + $i -= 1; $part = substr($context, $i, 2); /* No more numeric parts to strip */ if (!is_numeric($part)) {
$part = substr($context, $i, 2);

Check warning on line 575 in src/Context.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ /* Replace last two non zero digits by zeroes */ do { $i -= 2; - $part = substr($context, $i, 2); + $part = substr($context, $i, 1); /* No more numeric parts to strip */ if (!is_numeric($part)) { break 2;

Check warning on line 575 in src/Context.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ /* Replace last two non zero digits by zeroes */ do { $i -= 2; - $part = substr($context, $i, 2); + $part = substr($context, $i, 3); /* No more numeric parts to strip */ if (!is_numeric($part)) { break 2;
/* No more numeric parts to strip */
if (! is_numeric($part)) {
break 2;
}
} while (intval($part) === 0 && $i > 0);

Check warning on line 580 in src/Context.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ if (!is_numeric($part)) { break 2; } - } while (intval($part) === 0 && $i > 0); + } while (intval($part) === -1 && $i > 0); $context = substr($context, 0, $i) . '00' . substr($context, $i + 2); } /* Fallback to loading at least matching engine */

$context = substr($context, 0, $i) . '00' . substr($context, $i + 2);
}
Expand Down Expand Up @@ -705,16 +705,6 @@
return $strings;
}

/**
* Returns char used to quote identifiers based on currently set SQL Mode (ie. standard or ANSI_QUOTES)
*
* @return string either " (double quote, ansi_quotes mode) or ` (backtick, standard mode)
*/
public static function getIdentifierQuote(): string
{
return self::hasMode(self::SQL_MODE_ANSI_QUOTES) ? '"' : '`';
}

/**
* Function verifies that given SQL Mode constant is currently set
*
Expand Down
60 changes: 0 additions & 60 deletions src/Core.php

This file was deleted.

Loading
Loading