fix issues found by phpstan

This commit is contained in:
Jan Tvrdik 2018-04-30 12:37:48 +02:00
parent 0a3911f7a6
commit aa22c2f688
2 changed files with 8 additions and 4 deletions

View File

@ -83,15 +83,16 @@ class Lexer
public function tokenize(string $s): array
{
if ($this->regexp === null) {
if ($this->regexp === null || $this->types === null) {
$this->initialize();
}
assert($this->regexp !== null);
assert($this->types !== null);
preg_match_all($this->regexp, $s, $tokens, PREG_SET_ORDER);
assert($this->types !== null);
$count = count($this->types);
foreach ($tokens as &$match) {
for ($i = 1; $i <= $count; $i++) {
if ($match[$i] !== null && $match[$i] !== '') {

View File

@ -31,9 +31,12 @@ class ParserException extends \Exception
$this->currentOffset = $currentOffset;
$this->expectedTokenType = $expectedTokenType;
$json = json_encode($currentTokenValue, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
assert($json !== false);
parent::__construct(sprintf(
'Unexpected token %s, expected %s at offset %d',
json_encode($currentTokenValue, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
$json,
Lexer::TOKEN_LABELS[$expectedTokenType],
$currentOffset
));