Skip to content

Commit a79095e

Browse files
Merge pull request #525 from kamil-tekiela/types-in-exceptions
Add native property types in Exceptions
2 parents 72699fb + bdf7b67 commit a79095e

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed

phpstan-baseline.neon

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,6 @@ parameters:
370370
count: 1
371371
path: src/Context.php
372372

373-
-
374-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Exceptions\\\\ParserException\\:\\:\\$token \\(PhpMyAdmin\\\\SqlParser\\\\Token\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
375-
count: 1
376-
path: src/Exceptions/ParserException.php
377-
378373
-
379374
message: "#^Cannot access property \\$type on PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
380375
count: 2
@@ -700,6 +695,16 @@ parameters:
700695
count: 2
701696
path: src/Utils/CLI.php
702697

698+
-
699+
message: "#^Cannot access property \\$position on PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
700+
count: 1
701+
path: src/Utils/Error.php
702+
703+
-
704+
message: "#^Cannot access property \\$token on PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
705+
count: 1
706+
path: src/Utils/Error.php
707+
703708
-
704709
message: "#^Argument of an invalid type array\\<int, array\\<string, int\\|string\\>\\>\\|bool\\|string supplied for foreach, only iterables are supported\\.$#"
705710
count: 1

psalm-baseline.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,6 @@
556556
<code>ContextMySql80100</code>
557557
</UnusedClass>
558558
</file>
559-
<file src="src/Exceptions/ParserException.php">
560-
<PossiblyNullPropertyAssignmentValue>
561-
<code>$token</code>
562-
</PossiblyNullPropertyAssignmentValue>
563-
</file>
564559
<file src="src/Lexer.php">
565560
<LoopInvalidation>
566561
<code><![CDATA[$this->last]]></code>
@@ -1029,6 +1024,10 @@
10291024
<code>$err[1]</code>
10301025
<code>$err[3]</code>
10311026
</PossiblyNullArgument>
1027+
<PossiblyNullPropertyFetch>
1028+
<code><![CDATA[$err->token->position]]></code>
1029+
<code><![CDATA[$err->token->token]]></code>
1030+
</PossiblyNullPropertyFetch>
10321031
<RedundantConditionGivenDocblockType>
10331032
<code>$obj instanceof Parser</code>
10341033
</RedundantConditionGivenDocblockType>

src/Exceptions/LexerException.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@ class LexerException extends Exception
1313
{
1414
/**
1515
* The character that produced this error.
16-
*
17-
* @var string
1816
*/
19-
public $ch;
17+
public string $ch;
2018

2119
/**
2220
* The index of the character that produced this error.
23-
*
24-
* @var int
2521
*/
26-
public $pos;
22+
public int $pos;
2723

2824
/**
2925
* @param string $msg the message of this exception

src/Exceptions/ParserException.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ class ParserException extends Exception
1414
{
1515
/**
1616
* The token that produced this error.
17-
*
18-
* @var Token
1917
*/
20-
public $token;
18+
public Token|null $token;
2119

2220
/**
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
21+
* @param string $msg the message of this exception
22+
* @param Token|null $token the token that produced this exception
23+
* @param int $code the code of this error
2624
*/
27-
public function __construct(string $msg = '', Token|null $token = null, int $code = 0)
25+
public function __construct(string $msg, Token|null $token, int $code = 0)
2826
{
2927
parent::__construct($msg, $code);
3028

src/Tools/TestGenerator.php

Lines changed: 1 addition & 1 deletion
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(string $query, string $type = 'parser'): array
5252
{

tests/TestCase.php

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

0 commit comments

Comments
 (0)