From a7eddceb079d2c3ea54cf3d7906fdaab96b84677 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 15 Jan 2024 21:25:16 +0100 Subject: [PATCH 1/2] Add native property types in Exceptions Signed-off-by: Kamil Tekiela --- src/Exceptions/LexerException.php | 8 ++------ src/Exceptions/ParserException.php | 10 ++++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Exceptions/LexerException.php b/src/Exceptions/LexerException.php index abb87aa1..3ad0328e 100644 --- a/src/Exceptions/LexerException.php +++ b/src/Exceptions/LexerException.php @@ -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 diff --git a/src/Exceptions/ParserException.php b/src/Exceptions/ParserException.php index 0341f8f8..c0bce98c 100644 --- a/src/Exceptions/ParserException.php +++ b/src/Exceptions/ParserException.php @@ -14,15 +14,13 @@ 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) { From bdf7b67062a55dfca92e8addd7d56c423eac8bcb Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 15 Jan 2024 21:39:57 +0100 Subject: [PATCH 2/2] Fix SA issues Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 15 ++++++++++----- psalm-baseline.xml | 9 ++++----- src/Exceptions/ParserException.php | 2 +- src/Tools/TestGenerator.php | 2 +- tests/TestCase.php | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 825d3e39..80ff745a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 @@ -710,6 +705,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\\\\>\\|bool\\|string supplied for foreach, only iterables are supported\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d769180a..ce8a116d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -561,11 +561,6 @@ ContextMySql80100 - - - $token - - last]]> @@ -1038,6 +1033,10 @@ $err[1] $err[3] + + token->position]]> + token->token]]> + $obj instanceof Parser diff --git a/src/Exceptions/ParserException.php b/src/Exceptions/ParserException.php index c0bce98c..bad07139 100644 --- a/src/Exceptions/ParserException.php +++ b/src/Exceptions/ParserException.php @@ -22,7 +22,7 @@ class ParserException extends 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); diff --git a/src/Tools/TestGenerator.php b/src/Tools/TestGenerator.php index b6dc65c4..0734698e 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(string $query, string $type = 'parser'): array { diff --git a/tests/TestCase.php b/tests/TestCase.php index 45f14c31..abbd322e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -56,7 +56,7 @@ public function getTokensList(string $query): TokensList * @psalm-return ( * $obj is Lexer * ? list - * : list + * : list * ) */ public function getErrorsAsArray($obj): array