diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 419731eec..878a51123 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -465,11 +465,6 @@ parameters:
count: 1
path: src/Context.php
- -
- message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Exceptions\\\\ParserException\\:\\:\\$token \\(PhpMyAdmin\\\\SqlParser\\\\Token\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
- count: 1
- path: src/Exceptions/ParserException.php
-
-
message: "#^Cannot access property \\$type on PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
count: 2
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index ee64ca7a1..80d5bdb4a 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -656,11 +656,6 @@
-
-
- $token
-
-
$this->last
diff --git a/src/Exceptions/ParserException.php b/src/Exceptions/ParserException.php
index 7bf067923..8e2892898 100644
--- a/src/Exceptions/ParserException.php
+++ b/src/Exceptions/ParserException.php
@@ -15,14 +15,14 @@ class ParserException extends Exception
/**
* The token that produced this error.
*
- * @var Token
+ * @var Token|null
*/
public $token;
/**
- * @param string $msg the message of this exception
- * @param Token $token the token that produced this exception
- * @param int $code the code of this error
+ * @param string $msg the message of this exception
+ * @param Token|null $token the token that produced this exception
+ * @param int $code the code of this error
*/
public function __construct($msg = '', ?Token $token = null, $code = 0)
{
diff --git a/src/Tools/TestGenerator.php b/src/Tools/TestGenerator.php
index 46b70f98c..1fa924d20 100644
--- a/src/Tools/TestGenerator.php
+++ b/src/Tools/TestGenerator.php
@@ -46,7 +46,7 @@ class TestGenerator
* @param string $query the query to be analyzed
* @param string $type test's type (may be `lexer` or `parser`)
*
- * @return array>>|null>
+ * @return array>>|null>
*/
public static function generate($query, $type = 'parser')
{
@@ -72,8 +72,6 @@ public static function generate($query, $type = 'parser')
/**
* Parser's errors.
- *
- * @var array>
*/
$parserErrors = [];
diff --git a/src/Utils/Error.php b/src/Utils/Error.php
index 1b52b4d1c..f52b91ccd 100644
--- a/src/Utils/Error.php
+++ b/src/Utils/Error.php
@@ -50,8 +50,8 @@ public static function get($objs)
$ret[] = [
$err->getMessage(),
$err->getCode(),
- $err->token->token,
- $err->token->position,
+ $err->token !== null ? $err->token->token : '',
+ $err->token !== null ? $err->token->position : null,
];
}
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index fc196ae24..8351a84b8 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -57,7 +57,7 @@ public function getTokensList(string $query): TokensList
* @psalm-return (
* $obj is Lexer
* ? list
- * : list
+ * : list
* )
*/
public function getErrorsAsArray($obj): array
diff --git a/tests/Utils/ErrorTest.php b/tests/Utils/ErrorTest.php
index dce85da1f..f3769891c 100644
--- a/tests/Utils/ErrorTest.php
+++ b/tests/Utils/ErrorTest.php
@@ -34,6 +34,16 @@ public function testGet(): void
);
}
+ public function testGetWithNullToken(): void
+ {
+ $lexer = new Lexer('LOCK TABLES table1 AS `t1` LOCAL');
+ $parser = new Parser($lexer->list);
+ $this->assertEquals(
+ [['Unexpected keyword.', 0, 'LOCAL', 27], ['Unexpected end of LOCK expression.', 0, null, null]],
+ Error::get([$lexer, $parser])
+ );
+ }
+
public function testFormat(): void
{
$this->assertEquals(