Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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\\<non\\-empty\\-string, int\\> and array\\{\\} will always evaluate to false\\.$#"
count: 1
Expand Down
4 changes: 0 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@
<code>$token</code>
</PossiblyNullArgument>
<PossiblyNullOperand>
<code><![CDATA[$this->delimiter]]></code>
<code><![CDATA[$this->str[$this->last++]]]></code>
<code><![CDATA[$this->str[$this->last++]]]></code>
<code><![CDATA[$this->str[$this->last]]]></code>
Expand All @@ -616,9 +615,6 @@
<code><![CDATA[$this->str[++$this->last]]]></code>
<code><![CDATA[$this->str[++$this->last]]]></code>
</PossiblyNullOperand>
<PossiblyNullPropertyAssignmentValue>
<code>null</code>
</PossiblyNullPropertyAssignmentValue>
<PossiblyNullPropertyFetch>
<code><![CDATA[$next->type]]></code>
<code><![CDATA[$next->value]]></code>
Expand Down
32 changes: 9 additions & 23 deletions src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,60 +66,46 @@ 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.
*
* 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
Expand Down Expand Up @@ -253,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
Expand All @@ -264,7 +250,7 @@ public function lex(): void
++$delimiterLen;
}

if (empty($this->delimiter)) {
if ($this->delimiter === '') {
$this->error('Expected delimiter.', '', $this->last);
$this->delimiter = ';';
}
Expand Down