Skip to content

Commit f6f48ae

Browse files
committed
ReferencedNameHelper: goto label should not be resolved as constant
1 parent 9bcf930 commit f6f48ae

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

SlevomatCodingStandard/Helpers/ReferencedNameHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ private static function isReferencedName(\PHP_CodeSniffer\Files\File $phpcsFile,
205205
}
206206
} elseif ($previousToken['code'] === T_BITWISE_AND && TokenHelper::findPreviousLocal($phpcsFile, [T_FUNCTION], $previousPointer - 1) !== null) {
207207
return false;
208+
} elseif ($previousToken['code'] === T_GOTO) {
209+
return false;
208210
}
209211

210212
$isProbablyReferencedName = !in_array(

tests/Helpers/ReferencedNameHelperTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,13 @@ public function testMethodReturningReferenceIsNotReferencedName(): void
154154
self::assertCount(0, $names);
155155
}
156156

157+
public function testGotoLabelIsNotReferencedName(): void
158+
{
159+
$codeSnifferFile = $this->getCodeSnifferFile(
160+
__DIR__ . '/data/goto.php'
161+
);
162+
$names = ReferencedNameHelper::getAllReferencedNames($codeSnifferFile, 0);
163+
self::assertCount(0, $names);
164+
}
165+
157166
}

tests/Helpers/data/goto.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
LABEL:
4+
5+
if (true) {
6+
goto LABEL;
7+
}

0 commit comments

Comments
 (0)