Skip to content

Commit 62965ec

Browse files
committed
TASK: Add suggestions from code review
1 parent 5819eb7 commit 62965ec

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/Parser/Tokenizer/Tokenizer.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,18 @@ private static function string(\Iterator $fragments): \Iterator
139139
$buffer->append($fragments->current());
140140
$fragments->next();
141141

142+
if (!$fragments->valid()) {
143+
throw new \Exception("@TODO: Unexpected end of input");
144+
}
145+
142146
$buffer->append($fragments->current());
143147
$fragments->next();
144148
break;
145149

146150
default:
147151
$buffer->append($fragments->current());
148152
$fragments->next();
153+
break;
149154
}
150155
}
151156
}
@@ -176,6 +181,11 @@ public static function templateLiteral(\Iterator $fragments): \Iterator
176181
case '$':
177182
$dollarSignBuffer = Buffer::empty()->append($fragments->current());
178183
$fragments->next();
184+
185+
if (!$fragments->valid()) {
186+
throw new \Exception("@TODO: Unexpected end of input");
187+
}
188+
179189
$nextFragment = $fragments->current();
180190

181191
if ($nextFragment->value === '{') {
@@ -189,13 +199,18 @@ public static function templateLiteral(\Iterator $fragments): \Iterator
189199
$buffer->append($fragments->current());
190200
$fragments->next();
191201

202+
if (!$fragments->valid()) {
203+
throw new \Exception("@TODO: Unexpected end of input");
204+
}
205+
192206
$buffer->append($fragments->current());
193207
$fragments->next();
194208
break;
195209

196210
default:
197211
$buffer->append($fragments->current());
198212
$fragments->next();
213+
break;
199214
}
200215
}
201216
}

0 commit comments

Comments
 (0)