Skip to content

Commit

Permalink
Merge branch 'master' into More-refactoring-of-build-method
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioFauth authored Sep 16, 2023
2 parents 08a480c + 26b7bee commit efcafa1
Show file tree
Hide file tree
Showing 71 changed files with 976 additions and 341 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
- Move `Misc::getAliases()` into `SelectStatement::getAliases()` (#454)
- Drop `USE_UTF_STRINGS` constant (#471)

## [5.x.x] - YYYY-MM-DD
## [5.9.x] - YYYY-MM-DD

## [5.8.x] - YYYY-MM-DD

## [5.8.1] - 2023-09-15

- Fix `:=` was not recognized as an operator just like `=` (#306)
- Fix `ALTER TABLE … MODIFY … ENUM('<reserved_keyword>')` is being wrongly parsed (#234)
- Fix `ALTER TABLE … MODIFY … ENUM('<reserved_keyword>')` is being wrongly parsed (#478)
- Fix MariaDB window function with alias gives bad linting errors (#283)
- Fix unrecognized keyword `COLLATE` in `WHERE` clauses (#491)
- Fix invalid hexadecimal prefix 0X (#508)

## [5.8.0] - 2023-06-05

Expand Down
3 changes: 0 additions & 3 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
<severity>4</severity>
</rule>
<rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps">
<severity>4</severity>
</rule>
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ parameters:
count: 3
path: src/Components/AlterOperation.php

-
message: "#^Parameter \\#1 \\$key of function array_key_exists expects int\\|string, float\\|int\\|string given\\.$#"
count: 2
path: src/Components/AlterOperation.php

-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\AlterOperation\\:\\:\\$options \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
count: 1
Expand Down
9 changes: 0 additions & 9 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
'DO' => 10,
]]]></code>
</InvalidPropertyAssignmentValue>
<MixedArrayOffset>
<code><![CDATA[Parser::$statementParsers[$token->value]]]></code>
</MixedArrayOffset>
<PossiblyInvalidArgument>
<code>$arrayKey</code>
</PossiblyInvalidArgument>
Expand Down Expand Up @@ -773,9 +770,6 @@
<code>$built[$field]</code>
<code><![CDATA[$parsedClauses[$token->value]]]></code>
</InvalidArgument>
<MethodSignatureMustProvideReturnType>
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
<MixedArrayOffset>
<code><![CDATA[$parsedClauses[$token->value]]]></code>
<code><![CDATA[$parsedClauses[$token->value]]]></code>
Expand Down Expand Up @@ -1127,9 +1121,6 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="src/UtfString.php">
<MethodSignatureMustProvideReturnType>
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
<PossiblyUnusedProperty>
<code>$byteLen</code>
</PossiblyUnusedProperty>
Expand Down
4 changes: 1 addition & 3 deletions src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ interface Component extends Stringable
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return mixed
*/
public static function parse(Parser $parser, TokensList $list, array $options = []);
public static function parse(Parser $parser, TokensList $list, array $options = []): mixed;

/**
* Builds the string representation of a component of this type.
Expand Down
10 changes: 4 additions & 6 deletions src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use function array_key_exists;
use function in_array;
use function is_numeric;
use function is_int;
use function is_string;
use function trim;

Expand Down Expand Up @@ -300,10 +300,8 @@ public function __construct(
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return AlterOperation
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): AlterOperation
{
$ret = new static();

Expand Down Expand Up @@ -410,7 +408,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =

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

Check warning on line 411 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 411 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 411 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 411 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 411 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 @@ -443,7 +441,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
);
break;
}
} elseif (! empty(Parser::$statementParsers[$token->value])) {
} elseif (! empty(Parser::$statementParsers[$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 Down
6 changes: 5 additions & 1 deletion src/Components/ArrayObj.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(array $raw = [], array $values = [])
*
* @return ArrayObj|Component[]
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): ArrayObj|array
{
$ret = empty($options['type']) ? new static() : [];

Expand Down Expand Up @@ -89,6 +89,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =

// End of statement.
if ($token->type === Token::TYPE_DELIMITER) {
if ($brackets > 0) {
$parser->error('A closing bracket was expected.', $token);
}

break;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Components/CaseExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ final class CaseExpression implements Component
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return CaseExpression
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): CaseExpression
{
$ret = new static();

Expand Down
2 changes: 1 addition & 1 deletion src/Components/CreateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function __construct(
*
* @return CreateDefinition[]
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): array
{
$ret = [];

Expand Down
4 changes: 1 addition & 3 deletions src/Components/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ public function __construct(
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return DataType|null
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): DataType|null
{
$ret = new static();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/FunctionCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ public function __construct($name = null, $parameters = null)
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return FunctionCall
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): FunctionCall
{
$ret = new static();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/IntoKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ public function __construct(
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return IntoKeyword
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): IntoKeyword
{
$ret = new static();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ public function __construct(
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return Key
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): Key
{
$ret = new static();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ public function __construct($rowCount = 0, $offset = 0)
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return Limit
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): Limit
{
$ret = new static();

Expand Down
9 changes: 2 additions & 7 deletions src/Components/LockExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ final class LockExpression implements Component
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return LockExpression
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): LockExpression
{
$ret = new static();

Expand Down Expand Up @@ -106,10 +104,7 @@ public static function buildAll(array $component): string
return implode(', ', $component);
}

/**
* @return string
*/
private static function parseLockType(Parser $parser, TokensList $list)
private static function parseLockType(Parser $parser, TokensList $list): string
{
$lockType = '';

Expand Down
8 changes: 2 additions & 6 deletions src/Components/OptionsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ public function __construct(public array $options = [])
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return OptionsArray
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): OptionsArray
{
$ret = new static();

Expand Down Expand Up @@ -292,10 +290,8 @@ public function build(): string
* @param string $key the key to be checked
* @param bool $getExpr Gets the expression instead of the value.
* The value is the processed form of the expression.
*
* @return mixed
*/
public function has($key, $getExpr = false)
public function has($key, $getExpr = false): mixed
{
foreach ($this->options as $option) {
if (is_array($option)) {
Expand Down
4 changes: 1 addition & 3 deletions src/Components/PartitionDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ final class PartitionDefinition implements Component
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return PartitionDefinition
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): PartitionDefinition
{
$ret = new static();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ public function __construct($table = null, array $columns = [], $options = null)
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return Reference
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): Reference
{
$ret = new static();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/UnionKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ final class UnionKeyword implements Component
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return mixed
*
* @throws RuntimeException not implemented yet.
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): mixed
{
throw new RuntimeException(Translator::gettext('Not implemented yet.'));
}
Expand Down
4 changes: 1 addition & 3 deletions src/Components/WithKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ public function __construct(string $name)
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $options parameters for parsing
*
* @return mixed
*
* @throws RuntimeException not implemented yet.
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = []): mixed
{
throw new RuntimeException(Translator::gettext('Not implemented yet.'));
}
Expand Down
16 changes: 12 additions & 4 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use function intval;
use function is_int;
use function is_numeric;
use function preg_match;
use function str_replace;
use function str_starts_with;
use function strlen;
Expand Down Expand Up @@ -670,12 +671,14 @@ private static function getModeFromString(string $mode): int
*
* @param string $str the string to be escaped
* @param string $quote quote to be used when escaping
*
* @return string
*/
public static function escape(string $str, string $quote = '`')
public static function escape(string $str, string $quote = '`'): string
{
if ((static::$mode & self::SQL_MODE_NO_ENCLOSING_QUOTES) && (! static::isKeyword($str, true))) {
if (
(static::$mode & self::SQL_MODE_NO_ENCLOSING_QUOTES) && ! (
static::isKeyword($str, true) || self::doesIdentifierRequireQuoting($str)
)
) {
return $str;
}

Expand Down Expand Up @@ -727,4 +730,9 @@ public static function hasMode(int|null $flag = null): bool

return (self::$mode & $flag) === $flag;
}

private static function doesIdentifierRequireQuoting(string $identifier): bool
{
return preg_match('/^[$]|^\d+$|[^0-9a-zA-Z$_\x80-\xffff]/', $identifier) === 1;
}
}
14 changes: 7 additions & 7 deletions src/Contexts/ContextMariaDb100000.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class ContextMariaDb100000 extends Context
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
'ONE' => 1, 'ROW' => 1,
'BOOL' => 1, 'BYTE' => 1, 'CODE' => 1, 'CUBE' => 1, 'DATA' => 1, 'DISK' => 1,
'ENDS' => 1, 'FAST' => 1, 'FILE' => 1, 'FULL' => 1, 'HASH' => 1, 'HELP' => 1,
'HOST' => 1, 'LAST' => 1, 'LESS' => 1, 'LIST' => 1, 'LOGS' => 1, 'MODE' => 1,
'NAME' => 1, 'NEXT' => 1, 'NONE' => 1, 'OPEN' => 1, 'PAGE' => 1, 'PORT' => 1,
'PREV' => 1, 'ROWS' => 1, 'SLOW' => 1, 'SOME' => 1, 'STOP' => 1, 'THAN' => 1,
'TYPE' => 1, 'VIEW' => 1, 'WAIT' => 1, 'WORK' => 1, 'X509' => 1,
'BYTE' => 1, 'CODE' => 1, 'CUBE' => 1, 'DATA' => 1, 'DISK' => 1, 'ENDS' => 1,
'FAST' => 1, 'FILE' => 1, 'FULL' => 1, 'HASH' => 1, 'HELP' => 1, 'HOST' => 1,
'LAST' => 1, 'LESS' => 1, 'LIST' => 1, 'LOGS' => 1, 'MODE' => 1, 'NAME' => 1,
'NEXT' => 1, 'NONE' => 1, 'OPEN' => 1, 'PAGE' => 1, 'PORT' => 1, 'PREV' => 1,
'ROWS' => 1, 'SLOW' => 1, 'SOME' => 1, 'STOP' => 1, 'THAN' => 1, 'TYPE' => 1,
'VIEW' => 1, 'WAIT' => 1, 'WORK' => 1, 'X509' => 1,
'AFTER' => 1, 'BEGIN' => 1, 'BLOCK' => 1, 'BTREE' => 1, 'CACHE' => 1,
'CHAIN' => 1, 'CLOSE' => 1, 'ERROR' => 1, 'EVENT' => 1, 'EVERY' => 1,
'FIRST' => 1, 'FIXED' => 1, 'FLUSH' => 1, 'FOUND' => 1, 'HOSTS' => 1,
Expand Down Expand Up @@ -176,7 +176,7 @@ class ContextMariaDb100000 extends Context
'ON COMPLETION NOT PRESERVE' => 7,

'BIT' => 9, 'XML' => 9,
'ENUM' => 9, 'JSON' => 9, 'TEXT' => 9,
'BOOL' => 9, 'ENUM' => 9, 'JSON' => 9, 'TEXT' => 9,
'ARRAY' => 9,
'SERIAL' => 9,
'BOOLEAN' => 9,
Expand Down
Loading

0 comments on commit efcafa1

Please sign in to comment.