Skip to content

Commit f7c2e02

Browse files
committed
Fix unexpected behavior with comments
1 parent dac7a32 commit f7c2e02

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
UNRELEASED
5+
------------------
6+
7+
- Fix unexpected behavior with comments
8+
9+
410
1.1.1 (2024-06-24)
511
------------------
612

src/Converter.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,19 @@ protected static function extractArgsFromString(string $string): array
645645
$previousChar = $chars[$i - 1] ?? '';
646646
$nextChar = $chars[$i + 1] ?? '';
647647

648+
if ($inSinglelineComment || $inMultilineComment) {
649+
static::$hasComments = true;
650+
651+
if ($inSinglelineComment && $char === "\n") {
652+
$inSinglelineComment = false;
653+
654+
} elseif ($inMultilineComment && $previousChar === '*' && $char === '/') {
655+
$inMultilineComment = false;
656+
}
657+
658+
continue;
659+
}
660+
648661
if (! $inDoubleQuotedString && $char === "'" && $previousChar !== '\\') {
649662
$inSimpleQuotedString = ! $inSimpleQuotedString;
650663

@@ -665,30 +678,21 @@ protected static function extractArgsFromString(string $string): array
665678
} elseif ($char === ']') {
666679
$nbUnclosedBrackets--;
667680

668-
} elseif (! $inMultilineComment && ($char === '#' || $char === '/' && $nextChar === '/')) {
681+
} elseif ($char === '#' || $char === '/' && $nextChar === '/') {
669682
$inSinglelineComment = true;
683+
continue;
670684

671-
} elseif (! $inSinglelineComment && $char === '/' && $nextChar === '*') {
685+
} elseif ($char === '/' && $nextChar === '*') {
672686
$inMultilineComment = true;
687+
continue;
673688
}
674689
}
675690

676691
if ($nbUnclosedParenthesis < 0 || $nbUnclosedBrackets < 0) {
677692
throw new ConverterException();
678693
}
679694

680-
if (! $inSinglelineComment && ! $inMultilineComment) {
681-
$args[$argIndex] .= $char;
682-
} else {
683-
static::$hasComments = true;
684-
685-
if ($inSinglelineComment && $char === "\n") {
686-
$inSinglelineComment = false;
687-
688-
} elseif ($inMultilineComment && $previousChar === '*' && $char === '/') {
689-
$inMultilineComment = false;
690-
}
691-
}
695+
$args[$argIndex] .= $char;
692696
}
693697

694698
if (! $inSinglelineComment && ! $inMultilineComment

0 commit comments

Comments
 (0)