From 74e9a46e426bedaae3f60cc02da96f5a365f585a Mon Sep 17 00:00:00 2001 From: Andrea Marco Sartori Date: Sat, 25 Mar 2023 16:55:09 +1000 Subject: [PATCH] Simplify conditions --- src/Tokens/Lexer.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Tokens/Lexer.php b/src/Tokens/Lexer.php index e0677a7..267b2e4 100644 --- a/src/Tokens/Lexer.php +++ b/src/Tokens/Lexer.php @@ -47,7 +47,7 @@ final class Lexer implements IteratorAggregate /** * Retrieve the JSON fragments * - * @return Traversable + * @return \Generator */ public function getIterator(): Traversable { @@ -56,10 +56,8 @@ final class Lexer implements IteratorAggregate foreach ($this->source as $chunk) { for ($i = 0, $size = strlen($chunk); $i < $size; $i++, $this->position++) { - $character = $chunk[$i]; - $inString = ($character == '"' && $inString && $isEscaping) - || ($character != '"' && $inString) - || ($character == '"' && !$inString); + $isQuote = '"' == $character = $chunk[$i]; + $inString = $isQuote != $inString || ($isQuote && $inString && $isEscaping); $isEscaping = $character == '\\' && !$isEscaping; $shouldBuffer = $inString || !isset(Tokens::BOUNDARIES[$character]);