Skip to content
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 phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,6 @@
<file src="src/Contexts/ContextMySql80300.php">
<PropertyTypeCoercion occurrences="1"/>
</file>
<file src="src/Exceptions/ParserException.php">
<PossiblyNullPropertyAssignmentValue occurrences="1">
<code>$token</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="src/Lexer.php">
<LoopInvalidation occurrences="3">
<code>$this-&gt;last</code>
Expand Down
8 changes: 4 additions & 4 deletions src/Exceptions/ParserException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Tools/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string|Lexer|Parser|array<string, array<int, array<int, int|string|Token>>>|null>
* @return array<string, string|Lexer|Parser|array<string, array<int, array<int, int|string|Token|null>>>|null>
*/
public static function generate($query, $type = 'parser')
{
Expand All @@ -72,8 +72,6 @@ public static function generate($query, $type = 'parser')

/**
* Parser's errors.
*
* @var array<int, array<int, int|string|Token>>
*/
$parserErrors = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getTokensList(string $query): TokensList
* @psalm-return (
* $obj is Lexer
* ? list<array{string, string, int, int}>
* : list<array{string, Token, int}>
* : list<array{string, Token|null, int}>
* )
*/
public function getErrorsAsArray($obj): array
Expand Down
10 changes: 10 additions & 0 deletions tests/Utils/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down