99
1010/**
1111 * @author Tomasz Kowalczyk <tomasz@kowalczyk.cc>
12+ * @psalm-suppress PossiblyUndefinedArrayOffset
13+ * @psalm-suppress PossiblyUndefinedVariable
1214 */
1315final class RegularParser implements ParserInterface
1416{
@@ -79,6 +81,7 @@ public function parse($text)
7981 }
8082 }
8183 }
84+ /** @psalm-suppress PossiblyFalseArgument */
8285 ini_set ('xdebug.max_nesting_level ' , $ nestingLevel );
8386
8487 return $ shortcodes ;
@@ -269,7 +272,9 @@ private function getBacktrack()
269272 {
270273 $ position = array_pop ($ this ->backtracks );
271274 $ backtrack = '' ;
275+ /** @psalm-suppress PossiblyNullOperand */
272276 for ($ i = $ position ; $ i < $ this ->position ; $ i ++) {
277+ /** @psalm-suppress PossiblyNullArrayOffset */
273278 $ backtrack .= $ this ->tokens [$ i ][1 ];
274279 }
275280
@@ -285,13 +290,17 @@ private function backtrack($modifyPosition = true)
285290 {
286291 $ position = array_pop ($ this ->backtracks );
287292 if ($ modifyPosition ) {
293+ /** @psalm-suppress PossiblyNullPropertyAssignmentValue */
288294 $ this ->position = $ position ;
289295 }
290296
291297 $ backtrack = '' ;
298+ /** @psalm-suppress PossiblyNullOperand */
292299 for ($ i = $ position ; $ i < $ this ->lastBacktrack ; $ i ++) {
300+ /** @psalm-suppress PossiblyNullArrayOffset */
293301 $ backtrack .= $ this ->tokens [$ i ][1 ];
294302 }
303+ /** @psalm-suppress PossiblyNullPropertyAssignmentValue */
295304 $ this ->lastBacktrack = $ position ;
296305
297306 return $ backtrack ;
@@ -339,6 +348,7 @@ private function match($type, $ws)
339348 * @param string $text
340349 *
341350 * @psalm-return list<array{0:int,1:string,2:int}>
351+ * @psalm-suppress MixedReturnTypeCoercion
342352 */
343353 private function tokenize ($ text )
344354 {
@@ -362,21 +372,23 @@ private function tokenize($text)
362372 default : { throw new \RuntimeException ('Invalid token. ' ); }
363373 }
364374 $ tokens [] = array ($ type , $ token , $ position );
375+ /** @psalm-suppress MixedArgument */
365376 $ position += mb_strlen ($ token , 'utf-8 ' );
366377 }
367378
379+ /** @psalm-suppress MixedReturnTypeCoercion */
368380 return $ tokens ;
369381 }
370382
371383 /** @return non-empty-string */
372384 private function prepareLexer (SyntaxInterface $ syntax )
373385 {
374386 // FIXME: for some reason Psalm does not understand the `@psalm-var callable() $var` annotation
375- /** @psalm-suppress MissingClosureParamType, MissingClosureReturnType */
387+ /** @psalm-suppress MissingClosureParamType,MissingClosureReturnType,PossiblyNullOperand */
376388 $ group = function ($ text , $ group ) {
377389 return '(?< ' .(string )$ group .'> ' .preg_replace ('/(.)/us ' , '\\\\$0 ' , (string )$ text ).') ' ;
378390 };
379- /** @psalm-suppress MissingClosureParamType, MissingClosureReturnType */
391+ /** @psalm-suppress MissingClosureParamType,MissingClosureReturnType */
380392 $ quote = function ($ text ) {
381393 return preg_replace ('/(.)/us ' , '\\\\$0 ' , (string )$ text );
382394 };
@@ -388,6 +400,7 @@ private function prepareLexer(SyntaxInterface $syntax)
388400 $ quote ($ syntax ->getClosingTagMarker ()),
389401 $ quote ($ syntax ->getParameterValueSeparator ()),
390402 $ quote ($ syntax ->getParameterValueDelimiter ()),
403+ '\\\\' ,
391404 '\s+ ' ,
392405 )).').)+) ' ,
393406 '(?<ws>\s+) ' ,
0 commit comments