Skip to content

Commit 72699fb

Browse files
Merge pull request #524 from kamil-tekiela/types-in-context
Add native property types in context
2 parents 3b7191a + a764d81 commit 72699fb

28 files changed

+47
-64
lines changed

psalm-baseline.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,6 @@
546546
<code>ContextMySql50600</code>
547547
</UnusedClass>
548548
</file>
549-
<file src="src/Contexts/ContextMySql50700.php">
550-
<UnusedClass>
551-
<code>ContextMySql50700</code>
552-
</UnusedClass>
553-
</file>
554549
<file src="src/Contexts/ContextMySql80000.php">
555550
<UnusedClass>
556551
<code>ContextMySql80000</code>

src/Context.php

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace PhpMyAdmin\SqlParser;
66

7+
use PhpMyAdmin\SqlParser\Contexts\ContextMySql50700;
8+
79
use function class_exists;
810
use function explode;
911
use function in_array;
@@ -43,27 +45,16 @@ abstract class Context
4345
*/
4446
public const OPERATOR_MAX_LENGTH = 4;
4547

46-
/**
47-
* The name of the default content.
48-
*
49-
* @var string
50-
*/
51-
public static $defaultContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700';
52-
5348
/**
5449
* The name of the loaded context.
55-
*
56-
* @var string
5750
*/
58-
public static $loadedContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700';
51+
public static string $loadedContext = ContextMySql50700::class;
5952

6053
/**
6154
* The prefix concatenated to the context name when an incomplete class name
6255
* is specified.
63-
*
64-
* @var string
6556
*/
66-
public static $contextPrefix = '\\PhpMyAdmin\\SqlParser\\Contexts\\Context';
57+
public static string $contextPrefix = 'PhpMyAdmin\\SqlParser\\Contexts\\Context';
6758

6859
/**
6960
* List of keywords.
@@ -83,14 +74,14 @@ abstract class Context
8374
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
8475
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
8576
*/
86-
public static $keywords = [];
77+
public static array $keywords = [];
8778

8879
/**
8980
* List of operators and their flags.
9081
*
9182
* @var array<string, int>
9283
*/
93-
public static $operators = [
84+
public static array $operators = [
9485
// Some operators (*, =) may have ambiguous flags, because they depend on
9586
// the context they are being used in.
9687
// For example: 1. SELECT * FROM table; # SQL specific (wildcard)
@@ -144,10 +135,8 @@ abstract class Context
144135
*
145136
* @link https://dev.mysql.com/doc/refman/en/sql-mode.html
146137
* @link https://mariadb.com/kb/en/sql-mode/
147-
*
148-
* @var int
149138
*/
150-
public static $mode = self::SQL_MODE_NONE;
139+
public static int $mode = self::SQL_MODE_NONE;
151140

152141
public const SQL_MODE_NONE = 0;
153142

@@ -529,19 +518,19 @@ public static function isSeparator(string $string): bool
529518
*/
530519
public static function load(string $context = ''): bool
531520
{
532-
if (empty($context)) {
533-
$context = self::$defaultContext;
521+
if ($context === '') {
522+
$context = ContextMySql50700::class;
534523
}
535524

536-
if ($context[0] !== '\\') {
525+
if (! class_exists($context)) {
526+
if (! class_exists(self::$contextPrefix . $context)) {
527+
return false;
528+
}
529+
537530
// Short context name (must be formatted into class name).
538531
$context = self::$contextPrefix . $context;
539532
}
540533

541-
if (! class_exists($context)) {
542-
return false;
543-
}
544-
545534
self::$loadedContext = $context;
546535
self::$keywords = $context::$keywords;
547536

src/Contexts/ContextMariaDb100000.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ContextMariaDb100000 extends Context
3030
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
3131
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
3232
*/
33-
public static $keywords = [
33+
public static array $keywords = [
3434
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
3535
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
3636
'ONE' => 1, 'ROW' => 1,

src/Contexts/ContextMariaDb100100.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ContextMariaDb100100 extends Context
3030
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
3131
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
3232
*/
33-
public static $keywords = [
33+
public static array $keywords = [
3434
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
3535
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
3636
'ONE' => 1, 'ROW' => 1, 'XID' => 1,

src/Contexts/ContextMariaDb100200.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ContextMariaDb100200 extends Context
3030
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
3131
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
3232
*/
33-
public static $keywords = [
33+
public static array $keywords = [
3434
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
3535
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
3636
'ONE' => 1, 'ROW' => 1, 'XID' => 1,

src/Contexts/ContextMariaDb100300.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ContextMariaDb100300 extends Context
3030
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
3131
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
3232
*/
33-
public static $keywords = [
33+
public static array $keywords = [
3434
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
3535
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
3636
'ONE' => 1, 'ROW' => 1, 'XID' => 1,

src/Contexts/ContextMariaDb100400.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ContextMariaDb100400 extends Context
3030
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
3131
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
3232
*/
33-
public static $keywords = [
33+
public static array $keywords = [
3434
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
3535
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
3636
'ONE' => 1, 'ROW' => 1, 'XID' => 1,

src/Contexts/ContextMariaDb100500.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ContextMariaDb100500 extends Context
3030
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
3131
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
3232
*/
33-
public static $keywords = [
33+
public static array $keywords = [
3434
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
3535
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
3636
'ONE' => 1, 'ROW' => 1, 'XID' => 1,

src/Contexts/ContextMariaDb100600.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ContextMariaDb100600 extends Context
3030
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
3131
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
3232
*/
33-
public static $keywords = [
33+
public static array $keywords = [
3434
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
3535
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
3636
'ONE' => 1, 'ROW' => 1, 'XID' => 1,

src/Contexts/ContextMariaDb100700.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ContextMariaDb100700 extends Context
3030
* @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
3131
* @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
3232
*/
33-
public static $keywords = [
33+
public static array $keywords = [
3434
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
3535
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
3636
'ONE' => 1, 'ROW' => 1, 'XID' => 1,

0 commit comments

Comments
 (0)