From fe06c299ccf738ee0356fb8f05fa5ecefd79b52d Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 15 Jan 2024 21:58:13 +0100 Subject: [PATCH 1/2] Add native property types in Lexer Signed-off-by: Kamil Tekiela --- src/Lexer.php | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/Lexer.php b/src/Lexer.php index d6dab82d..15a75411 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -66,49 +66,37 @@ class Lexer /** * The string to be parsed. - * - * @var string|UtfString */ - public $str = ''; + public string|UtfString $str = ''; /** * The length of `$str`. * * By storing its length, a lot of time is saved, because parsing methods * would call `strlen` everytime. - * - * @var int */ - public $len = 0; + public int $len = 0; /** * The index of the last parsed character. - * - * @var int */ - public $last = 0; + public int $last = 0; /** * Tokens extracted from given strings. - * - * @var TokensList */ - public $list; + public TokensList $list; /** * The default delimiter. This is used, by default, in all new instances. - * - * @var string */ - public static $defaultDelimiter = ';'; + public static string $defaultDelimiter = ';'; /** * Statements delimiter. * This may change during lexing. - * - * @var string */ - public $delimiter; + public string $delimiter; /** * The length of the delimiter. @@ -116,10 +104,8 @@ class Lexer * Because `parseDelimiter` can be called a lot, it would perform a lot of * calls to `strlen`, which might affect performance when the delimiter is * big. - * - * @var int */ - public $delimiterLen; + public int $delimiterLen; /** * @param string|UtfString $str the query to be lexed From 5f7535e87bfbd857fba3a99d13582229301bd0d1 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 15 Jan 2024 22:02:54 +0100 Subject: [PATCH 2/2] Don't assign null to $delimiter Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 5 ----- psalm-baseline.xml | 4 ---- src/Lexer.php | 4 ++-- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f5cad29d..d02a09b1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -385,11 +385,6 @@ parameters: count: 3 path: src/Lexer.php - - - message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Lexer\\:\\:\\$delimiter \\(string\\) does not accept null\\.$#" - count: 1 - path: src/Lexer.php - - message: "#^Strict comparison using \\=\\=\\= between non\\-empty\\-array\\ and array\\{\\} will always evaluate to false\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 7ebdefa3..119e0f7a 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -590,7 +590,6 @@ $token - delimiter]]> str[$this->last++]]]> str[$this->last++]]]> str[$this->last]]]> @@ -616,9 +615,6 @@ str[++$this->last]]]> str[++$this->last]]]> - - null - type]]> value]]> diff --git a/src/Lexer.php b/src/Lexer.php index 15a75411..ab033a57 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -239,7 +239,7 @@ public function lex(): void $pos = $this->last + 1; // Parsing the delimiter. - $this->delimiter = null; + $this->delimiter = ''; $delimiterLen = 0; while ( ++$this->last < $this->len @@ -250,7 +250,7 @@ public function lex(): void ++$delimiterLen; } - if (empty($this->delimiter)) { + if ($this->delimiter === '') { $this->error('Expected delimiter.', '', $this->last); $this->delimiter = ';'; }