Skip to content

Commit 718b932

Browse files
committed
Merge branch 'php8.1/tokenizer-php-bugfix-enum-name-vs-goto-label' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 3e6ce10 + 4d0be7c commit 718b932

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

src/Tokenizers/PHP.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,7 @@ function return types. We want to keep the parenthesis map clean,
19051905
T_OPEN_TAG => true,
19061906
T_OPEN_CURLY_BRACKET => true,
19071907
T_INLINE_THEN => true,
1908+
T_ENUM => true,
19081909
];
19091910

19101911
for ($x = ($newStackPtr - 1); $x > 0; $x--) {
@@ -1915,6 +1916,7 @@ function return types. We want to keep the parenthesis map clean,
19151916

19161917
if ($finalTokens[$x]['code'] !== T_CASE
19171918
&& $finalTokens[$x]['code'] !== T_INLINE_THEN
1919+
&& $finalTokens[$x]['code'] !== T_ENUM
19181920
) {
19191921
$finalTokens[$newStackPtr] = [
19201922
'content' => $token[1].':',

tests/Core/Tokenizer/BackfillEnumTest.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ enum Boo: int {
1313
}
1414

1515
/* testBackedStringEnum */
16-
enum Hoo: string
16+
enum Hoo : string
1717
{
1818
case ONE = 'one';
1919
case TWO = 'two';

tests/Core/Tokenizer/BackfillEnumTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,20 @@ public function dataEnums()
8787
[
8888
'/* testBackedIntEnum */',
8989
'enum',
90-
6,
91-
28,
90+
7,
91+
29,
9292
],
9393
[
9494
'/* testBackedStringEnum */',
9595
'enum',
96-
6,
97-
28,
96+
8,
97+
30,
9898
],
9999
[
100100
'/* testComplexEnum */',
101101
'enum',
102-
10,
103-
71,
102+
11,
103+
72,
104104
],
105105
[
106106
'/* testEnumWithEnumAsClassName */',

tests/Core/Tokenizer/GotoLabelTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ switch (true) {
5151
// Do something.
5252
break;
5353
}
54+
55+
/* testNotGotoDeclarationEnumWithType */
56+
enum Suit: string implements Colorful, CardGame {}

tests/Core/Tokenizer/GotoLabelTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ public function dataNotAGotoDeclaration()
163163
'/* testNotGotoDeclarationGlobalConstantInTernary */',
164164
'CONST_B',
165165
],
166+
[
167+
'/* testNotGotoDeclarationEnumWithType */',
168+
'Suit',
169+
],
166170
];
167171

168172
}//end dataNotAGotoDeclaration()

0 commit comments

Comments
 (0)