Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -2271,6 +2271,7 @@ function return types. We want to keep the parenthesis map clean,
// Okay, so we have a colon, now we need to make sure that this is not
// class constant access, a ternary, enum or switch case.
$stopTokens = [
T_DOUBLE_COLON => true,
T_CASE => true,
T_SEMICOLON => true,
T_OPEN_TAG => true,
Expand All @@ -2285,7 +2286,8 @@ function return types. We want to keep the parenthesis map clean,
}
}

if ($finalTokens[$x]['code'] !== T_CASE
if ($finalTokens[$x]['code'] !== T_DOUBLE_COLON
&& $finalTokens[$x]['code'] !== T_CASE
&& $finalTokens[$x]['code'] !== T_INLINE_THEN
&& $finalTokens[$x]['code'] !== T_ENUM
) {
Expand Down
12 changes: 11 additions & 1 deletion tests/Core/Tokenizers/PHP/GotoLabelTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,21 @@ switch ($x) {
// Do something.
break;

/* testNotGotoDeclarationClassConstant */
/* testNotGotoDeclarationClassConstantInCase */
case MyClass::CONSTANT:
// Do something.
break;

/* testNotGotoDeclarationClassConstantWithSpace */
case MyClass :: MY_CONST:
// Do something.
break;

/* testNotGotoDeclarationClassConstantWithComment */
case MyClass::/*comment*/OTHER_CONST:
// Do something.
break;

/* testNotGotoDeclarationClassProperty */
case $obj->property:
// Do something.
Expand Down
10 changes: 9 additions & 1 deletion tests/Core/Tokenizers/PHP/GotoLabelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,17 @@ public static function dataNotAGotoDeclaration()
'testContent' => 'CONSTANT',
],
'not goto label - class constant followed by switch-case colon' => [
'testMarker' => '/* testNotGotoDeclarationClassConstant */',
'testMarker' => '/* testNotGotoDeclarationClassConstantInCase */',
'testContent' => 'CONSTANT',
],
'not goto label - spacey class constant in switch-case' => [
'testMarker' => '/* testNotGotoDeclarationClassConstantWithSpace */',
'testContent' => 'MY_CONST',
],
'not goto label - class constant with comment in switch-case' => [
'testMarker' => '/* testNotGotoDeclarationClassConstantWithComment */',
'testContent' => 'OTHER_CONST',
],
'not goto label - class property use followed by switch-case colon' => [
'testMarker' => '/* testNotGotoDeclarationClassProperty */',
'testContent' => 'property',
Expand Down