Skip to content

Commit 31bf535

Browse files
Merge pull request #528 from kamil-tekiela/types-in-Lexer
Add native property types in Lexer
2 parents be871d1 + 5f7535e commit 31bf535

File tree

3 files changed

+9
-32
lines changed

3 files changed

+9
-32
lines changed

‎phpstan-baseline.neon‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,6 @@ parameters:
380380
count: 3
381381
path: src/Lexer.php
382382

383-
-
384-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Lexer\\:\\:\\$delimiter \\(string\\) does not accept null\\.$#"
385-
count: 1
386-
path: src/Lexer.php
387-
388383
-
389384
message: "#^Strict comparison using \\=\\=\\= between non\\-empty\\-array\\<non\\-empty\\-string, int\\> and array\\{\\} will always evaluate to false\\.$#"
390385
count: 1

‎psalm-baseline.xml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@
585585
<code>$token</code>
586586
</PossiblyNullArgument>
587587
<PossiblyNullOperand>
588-
<code><![CDATA[$this->delimiter]]></code>
589588
<code><![CDATA[$this->str[$this->last++]]]></code>
590589
<code><![CDATA[$this->str[$this->last++]]]></code>
591590
<code><![CDATA[$this->str[$this->last]]]></code>
@@ -611,9 +610,6 @@
611610
<code><![CDATA[$this->str[++$this->last]]]></code>
612611
<code><![CDATA[$this->str[++$this->last]]]></code>
613612
</PossiblyNullOperand>
614-
<PossiblyNullPropertyAssignmentValue>
615-
<code>null</code>
616-
</PossiblyNullPropertyAssignmentValue>
617613
<PossiblyNullPropertyFetch>
618614
<code><![CDATA[$next->type]]></code>
619615
<code><![CDATA[$next->value]]></code>

‎src/Lexer.php‎

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,60 +66,46 @@ class Lexer
6666

6767
/**
6868
* The string to be parsed.
69-
*
70-
* @var string|UtfString
7169
*/
72-
public $str = '';
70+
public string|UtfString $str = '';
7371

7472
/**
7573
* The length of `$str`.
7674
*
7775
* By storing its length, a lot of time is saved, because parsing methods
7876
* would call `strlen` everytime.
79-
*
80-
* @var int
8177
*/
82-
public $len = 0;
78+
public int $len = 0;
8379

8480
/**
8581
* The index of the last parsed character.
86-
*
87-
* @var int
8882
*/
89-
public $last = 0;
83+
public int $last = 0;
9084

9185
/**
9286
* Tokens extracted from given strings.
93-
*
94-
* @var TokensList
9587
*/
96-
public $list;
88+
public TokensList $list;
9789

9890
/**
9991
* The default delimiter. This is used, by default, in all new instances.
100-
*
101-
* @var string
10292
*/
103-
public static $defaultDelimiter = ';';
93+
public static string $defaultDelimiter = ';';
10494

10595
/**
10696
* Statements delimiter.
10797
* This may change during lexing.
108-
*
109-
* @var string
11098
*/
111-
public $delimiter;
99+
public string $delimiter;
112100

113101
/**
114102
* The length of the delimiter.
115103
*
116104
* Because `parseDelimiter` can be called a lot, it would perform a lot of
117105
* calls to `strlen`, which might affect performance when the delimiter is
118106
* big.
119-
*
120-
* @var int
121107
*/
122-
public $delimiterLen;
108+
public int $delimiterLen;
123109

124110
/**
125111
* @param string|UtfString $str the query to be lexed
@@ -253,7 +239,7 @@ public function lex(): void
253239
$pos = $this->last + 1;
254240

255241
// Parsing the delimiter.
256-
$this->delimiter = null;
242+
$this->delimiter = '';
257243
$delimiterLen = 0;
258244
while (
259245
++$this->last < $this->len
@@ -264,7 +250,7 @@ public function lex(): void
264250
++$delimiterLen;
265251
}
266252

267-
if (empty($this->delimiter)) {
253+
if ($this->delimiter === '') {
268254
$this->error('Expected delimiter.', '', $this->last);
269255
$this->delimiter = ';';
270256
}

0 commit comments

Comments
 (0)