diff --git a/src/Tokenizers/PHP.php b/src/Tokenizers/PHP.php index ab43989f77..ae3bc2fbea 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -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, @@ -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 ) { diff --git a/tests/Core/Tokenizers/PHP/GotoLabelTest.inc b/tests/Core/Tokenizers/PHP/GotoLabelTest.inc index 98503faf28..0ad90816aa 100644 --- a/tests/Core/Tokenizers/PHP/GotoLabelTest.inc +++ b/tests/Core/Tokenizers/PHP/GotoLabelTest.inc @@ -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. diff --git a/tests/Core/Tokenizers/PHP/GotoLabelTest.php b/tests/Core/Tokenizers/PHP/GotoLabelTest.php index 7def591d4c..0f453ebcfa 100644 --- a/tests/Core/Tokenizers/PHP/GotoLabelTest.php +++ b/tests/Core/Tokenizers/PHP/GotoLabelTest.php @@ -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',