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 property types in context #524

Merged
merged 2 commits into from
Jan 16, 2024
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
5 changes: 0 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,6 @@
<code>ContextMySql50600</code>
</UnusedClass>
</file>
<file src="src/Contexts/ContextMySql50700.php">
<UnusedClass>
<code>ContextMySql50700</code>
</UnusedClass>
</file>
<file src="src/Contexts/ContextMySql80000.php">
<UnusedClass>
<code>ContextMySql80000</code>
Expand Down
39 changes: 14 additions & 25 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace PhpMyAdmin\SqlParser;

use PhpMyAdmin\SqlParser\Contexts\ContextMySql50700;

use function class_exists;
use function explode;
use function in_array;
Expand Down Expand Up @@ -43,27 +45,16 @@
*/
public const OPERATOR_MAX_LENGTH = 4;

/**
* The name of the default content.
*
* @var string
*/
public static $defaultContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700';

/**
* The name of the loaded context.
*
* @var string
*/
public static $loadedContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700';
public static string $loadedContext = ContextMySql50700::class;

/**
* The prefix concatenated to the context name when an incomplete class name
* is specified.
*
* @var string
*/
public static $contextPrefix = '\\PhpMyAdmin\\SqlParser\\Contexts\\Context';
public static string $contextPrefix = 'PhpMyAdmin\\SqlParser\\Contexts\\Context';

/**
* List of keywords.
Expand All @@ -83,14 +74,14 @@
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [];
public static array $keywords = [];

/**
* List of operators and their flags.
*
* @var array<string, int>
*/
public static $operators = [
public static array $operators = [
// Some operators (*, =) may have ambiguous flags, because they depend on
// the context they are being used in.
// For example: 1. SELECT * FROM table; # SQL specific (wildcard)
Expand Down Expand Up @@ -144,10 +135,8 @@
*
* @link https://dev.mysql.com/doc/refman/en/sql-mode.html
* @link https://mariadb.com/kb/en/sql-mode/
*
* @var int
*/
public static $mode = self::SQL_MODE_NONE;
public static int $mode = self::SQL_MODE_NONE;

public const SQL_MODE_NONE = 0;

Expand Down Expand Up @@ -510,7 +499,7 @@
{
// NOTES: Only non-alphanumeric ASCII characters may be separators.
// `~` is the last printable ASCII character.
return $string <= '~'

Check warning on line 502 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 All @@ -529,19 +518,19 @@
*/
public static function load(string $context = ''): bool
{
if (empty($context)) {
$context = self::$defaultContext;
if ($context === '') {
$context = ContextMySql50700::class;
}

if ($context[0] !== '\\') {
if (! class_exists($context)) {
if (! class_exists(self::$contextPrefix . $context)) {
return false;
}

// Short context name (must be formatted into class name).
$context = self::$contextPrefix . $context;
}

if (! class_exists($context)) {
return false;
}

self::$loadedContext = $context;
self::$keywords = $context::$keywords;

Expand All @@ -563,21 +552,21 @@
public static function loadClosest(string $context = ''): string|null
{
$length = strlen($context);
for ($i = $length; $i > 0;) {

Check warning on line 555 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 562 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 563 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 564 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 564 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 569 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 */

Check warning on line 569 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 @@ @@ if (!is_numeric($part)) { break 2; } - } while (intval($part) === 0 && $i > 0); + } while (intval($part) === 0 && $i >= 0); $context = substr($context, 0, $i) . '00' . substr($context, $i + 2); } /* Fallback to loading at least matching engine */

Check warning on line 569 in src/Context.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

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

Check warning on line 569 in src/Context.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalAndAllSubExprNegation": --- Original +++ New @@ @@ if (!is_numeric($part)) { break 2; } - } while (intval($part) === 0 && $i > 0); + } while (!(intval($part) === 0) && !($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
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb100000.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb100000 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb100100.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb100100 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb100200.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb100200 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb100300.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb100300 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb100400.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb100400 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb100500.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb100500 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb100600.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb100600 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb100700.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb100700 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb100800.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb100800 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb100900.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb100900 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb101000.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb101000 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb101100.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb101100 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb110000.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb110000 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb110100.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb110100 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMariaDb110200.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMariaDb110200 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMySql50000.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMySql50000 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'BDB' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1,
'NEW' => 1, 'ONE' => 1, 'ROW' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMySql50100.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMySql50100 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'BDB' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1,
'NEW' => 1, 'ONE' => 1, 'ROW' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMySql50500.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMySql50500 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMySql50600.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMySql50600 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMySql50700.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMySql50700 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMySql80000.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMySql80000 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Contexts/ContextMySql80100.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ContextMySql80100 extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'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, 'XID' => 1,
Expand Down
6 changes: 3 additions & 3 deletions src/Tools/ContextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ContextGenerator
*
* @var array<string, int>
*/
public static $labelsFlags = [
public static array $labelsFlags = [
'(R)' => 2, // reserved
'(D)' => 8, // data type
'(K)' => 16, // keyword
Expand All @@ -54,7 +54,7 @@ class ContextGenerator
*
* @var array<string, string>
*/
public static $links = [
public static array $links = [
'MySql50000' => 'https://dev.mysql.com/doc/refman/5.0/en/keywords.html',
'MySql50100' => 'https://dev.mysql.com/doc/refman/5.1/en/keywords.html',
'MySql50500' => 'https://dev.mysql.com/doc/refman/5.5/en/keywords.html',
Expand Down Expand Up @@ -121,7 +121,7 @@ class %2$s extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
%4$s ];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tools/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
Context::load('MariaDb' . $mariaDbVersion);
} else {
// Load the default context to be sure there is no side effects
Context::load('');
Context::load();

Check warning on line 172 in src/Tools/TestGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/Tools/TestGenerator.php#L172

Added line #L172 was not covered by tests
}

$test = static::generate($query, $type);
Expand Down
13 changes: 6 additions & 7 deletions tests/Lexer/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ public static function tearDownAfterClass(): void
public function testLoad(): void
{
// Default context is 5.7.0.
$this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700', Context::$loadedContext);
$this->assertEquals('PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700', Context::$loadedContext);
$this->assertArrayHasKey('STORED', Context::$keywords);
$this->assertArrayNotHasKey('AUTHORS', Context::$keywords);

// Restoring context.
Context::load('');
$this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700', Context::$defaultContext);
Context::load();
$this->assertArrayHasKey('STORED', Context::$keywords);
$this->assertArrayNotHasKey('AUTHORS', Context::$keywords);
}
Expand All @@ -39,12 +38,12 @@ public function testLoadClosest(string $context, string|null $expected): void
{
$this->assertEquals($expected, Context::loadClosest($context));
if ($expected !== null) {
$this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\Context' . $expected, Context::$loadedContext);
$this->assertEquals('PhpMyAdmin\\SqlParser\\Contexts\\Context' . $expected, Context::$loadedContext);
$this->assertTrue(class_exists(Context::$loadedContext));
}

// Restoring context.
Context::load('');
Context::load();
}

/**
Expand Down Expand Up @@ -89,10 +88,10 @@ public static function contextLoadingProvider(): array
public function testLoadAll(string $context): void
{
Context::load($context);
$this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\Context' . $context, Context::$loadedContext);
$this->assertEquals('PhpMyAdmin\\SqlParser\\Contexts\\Context' . $context, Context::$loadedContext);

// Restoring context.
Context::load('');
Context::load();
}

/** @return string[][] */
Expand Down
2 changes: 1 addition & 1 deletion tests/Tools/templates/TestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestContext extends Context
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
*/
public static $keywords = [
public static array $keywords = [
'NO_FLAG' => 1,

'RESERVED' => 3,
Expand Down
Loading