Skip to content

Commit abaa086

Browse files
committed
Fix PHP notice in Utils\Error::get()
PHP Notice: Trying to get property 'token' of non-object in src/Utils/Error.php on line 54 PHP Notice: Trying to get property 'position' of non-object in src/Utils/Error.php on line 55 Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent da696b6 commit abaa086

File tree

7 files changed

+18
-20
lines changed

7 files changed

+18
-20
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,6 @@ parameters:
465465
count: 1
466466
path: src/Context.php
467467

468-
-
469-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Exceptions\\\\ParserException\\:\\:\\$token \\(PhpMyAdmin\\\\SqlParser\\\\Token\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
470-
count: 1
471-
path: src/Exceptions/ParserException.php
472-
473468
-
474469
message: "#^Cannot access property \\$type on PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
475470
count: 2

psalm-baseline.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,6 @@
644644
<file src="src/Contexts/ContextMySql80100.php">
645645
<PropertyTypeCoercion occurrences="1"/>
646646
</file>
647-
<file src="src/Exceptions/ParserException.php">
648-
<PossiblyNullPropertyAssignmentValue occurrences="1">
649-
<code>$token</code>
650-
</PossiblyNullPropertyAssignmentValue>
651-
</file>
652647
<file src="src/Lexer.php">
653648
<LoopInvalidation occurrences="3">
654649
<code>$this-&gt;last</code>

src/Exceptions/ParserException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ class ParserException extends Exception
1515
/**
1616
* The token that produced this error.
1717
*
18-
* @var Token
18+
* @var Token|null
1919
*/
2020
public $token;
2121

2222
/**
23-
* @param string $msg the message of this exception
24-
* @param Token $token the token that produced this exception
25-
* @param int $code the code of this error
23+
* @param string $msg the message of this exception
24+
* @param Token|null $token the token that produced this exception
25+
* @param int $code the code of this error
2626
*/
2727
public function __construct($msg = '', ?Token $token = null, $code = 0)
2828
{

src/Tools/TestGenerator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TestGenerator
4646
* @param string $query the query to be analyzed
4747
* @param string $type test's type (may be `lexer` or `parser`)
4848
*
49-
* @return array<string, string|Lexer|Parser|array<string, array<int, array<int, int|string|Token>>>|null>
49+
* @return array<string, string|Lexer|Parser|array<string, array<int, array<int, int|string|Token|null>>>|null>
5050
*/
5151
public static function generate($query, $type = 'parser')
5252
{
@@ -72,8 +72,6 @@ public static function generate($query, $type = 'parser')
7272

7373
/**
7474
* Parser's errors.
75-
*
76-
* @var array<int, array<int, int|string|Token>>
7775
*/
7876
$parserErrors = [];
7977

src/Utils/Error.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public static function get($objs)
5050
$ret[] = [
5151
$err->getMessage(),
5252
$err->getCode(),
53-
$err->token->token,
54-
$err->token->position,
53+
$err->token !== null ? $err->token->token : '',
54+
$err->token !== null ? $err->token->position : null,
5555
];
5656
}
5757
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getTokensList(string $query): TokensList
5757
* @psalm-return (
5858
* $obj is Lexer
5959
* ? list<array{string, string, int, int}>
60-
* : list<array{string, Token, int}>
60+
* : list<array{string, Token|null, int}>
6161
* )
6262
*/
6363
public function getErrorsAsArray($obj): array

tests/Utils/ErrorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ public function testGet(): void
3434
);
3535
}
3636

37+
public function testGetWithNullToken(): void
38+
{
39+
$lexer = new Lexer('LOCK TABLES table1 AS `t1` LOCAL');
40+
$parser = new Parser($lexer->list);
41+
$this->assertEquals(
42+
[['Unexpected keyword.', 0, 'LOCAL', 27], ['Unexpected end of LOCK expression.', 0, null, null]],
43+
Error::get([$lexer, $parser])
44+
);
45+
}
46+
3747
public function testFormat(): void
3848
{
3949
$this->assertEquals(

0 commit comments

Comments
 (0)