Skip to content

Commit

Permalink
Merge pull request #525 from kamil-tekiela/types-in-exceptions
Browse files Browse the repository at this point in the history
Add native property types in Exceptions
  • Loading branch information
MauricioFauth authored Jan 16, 2024
2 parents 72699fb + bdf7b67 commit a79095e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
15 changes: 10 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,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 Expand Up @@ -700,6 +695,16 @@ parameters:
count: 2
path: src/Utils/CLI.php

-
message: "#^Cannot access property \\$position on PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
count: 1
path: src/Utils/Error.php

-
message: "#^Cannot access property \\$token on PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
count: 1
path: src/Utils/Error.php

-
message: "#^Argument of an invalid type array\\<int, array\\<string, int\\|string\\>\\>\\|bool\\|string supplied for foreach, only iterables are supported\\.$#"
count: 1
Expand Down
9 changes: 4 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,6 @@
<code>ContextMySql80100</code>
</UnusedClass>
</file>
<file src="src/Exceptions/ParserException.php">
<PossiblyNullPropertyAssignmentValue>
<code>$token</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="src/Lexer.php">
<LoopInvalidation>
<code><![CDATA[$this->last]]></code>
Expand Down Expand Up @@ -1029,6 +1024,10 @@
<code>$err[1]</code>
<code>$err[3]</code>
</PossiblyNullArgument>
<PossiblyNullPropertyFetch>
<code><![CDATA[$err->token->position]]></code>
<code><![CDATA[$err->token->token]]></code>
</PossiblyNullPropertyFetch>
<RedundantConditionGivenDocblockType>
<code>$obj instanceof Parser</code>
</RedundantConditionGivenDocblockType>
Expand Down
8 changes: 2 additions & 6 deletions src/Exceptions/LexerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ class LexerException extends Exception
{
/**
* The character that produced this error.
*
* @var string
*/
public $ch;
public string $ch;

/**
* The index of the character that produced this error.
*
* @var int
*/
public $pos;
public int $pos;

/**
* @param string $msg the message of this exception
Expand Down
12 changes: 5 additions & 7 deletions src/Exceptions/ParserException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ class ParserException extends Exception
{
/**
* The token that produced this error.
*
* @var Token
*/
public $token;
public Token|null $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(string $msg = '', Token|null $token = null, int $code = 0)
public function __construct(string $msg, Token|null $token, int $code = 0)
{
parent::__construct($msg, $code);

Expand Down
2 changes: 1 addition & 1 deletion 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(string $query, string $type = 'parser'): array
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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

0 comments on commit a79095e

Please sign in to comment.