Skip to content

Commit d73a063

Browse files
committed
Merge branch 'php81-enum' of https://github.com/kukulich/PHP_CodeSniffer
2 parents 1900302 + 15a0b4e commit d73a063

File tree

89 files changed

+462
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+462
-36
lines changed

package.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
10151015
<file baseinstalldir="PHP/CodeSniffer" name="ClassCommentUnitTest.php" role="test" />
10161016
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.inc" role="test" />
10171017
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.2.inc" role="test" />
1018+
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.3.inc" role="test" />
10181019
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.php" role="test" />
10191020
<file baseinstalldir="PHP/CodeSniffer" name="FunctionCommentUnitTest.inc" role="test" />
10201021
<file baseinstalldir="PHP/CodeSniffer" name="FunctionCommentUnitTest.inc.fixed" role="test" />
@@ -1103,6 +1104,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
11031104
<dir name="Classes">
11041105
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.1.inc" role="test" />
11051106
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.2.inc" role="test" />
1107+
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.3.inc" role="test" />
11061108
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.php" role="test" />
11071109
</dir>
11081110
<dir name="Files">
@@ -1654,6 +1656,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
16541656
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.6.inc" role="test" />
16551657
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.7.inc" role="test" />
16561658
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.8.inc" role="test" />
1659+
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.9.inc" role="test" />
16571660
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.js" role="test" />
16581661
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.js.fixed" role="test" />
16591662
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.2.js" role="test" />
@@ -1771,6 +1774,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
17711774
<file baseinstalldir="PHP/CodeSniffer" name="FileExtensionUnitTest.2.inc" role="test" />
17721775
<file baseinstalldir="PHP/CodeSniffer" name="FileExtensionUnitTest.3.inc" role="test" />
17731776
<file baseinstalldir="PHP/CodeSniffer" name="FileExtensionUnitTest.4.inc" role="test" />
1777+
<file baseinstalldir="PHP/CodeSniffer" name="FileExtensionUnitTest.5.inc" role="test" />
17741778
<file baseinstalldir="PHP/CodeSniffer" name="FileExtensionUnitTest.php" role="test" />
17751779
</dir>
17761780
<dir name="Formatting">

src/Files/File.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ public function getFilename()
12231223

12241224

12251225
/**
1226-
* Returns the declaration names for classes, interfaces, traits, and functions.
1226+
* Returns the declaration name for classes, interfaces, traits, enums, and functions.
12271227
*
12281228
* @param int $stackPtr The position of the declaration token which
12291229
* declared the class, interface, trait, or function.
@@ -1232,7 +1232,7 @@ public function getFilename()
12321232
* or NULL if the function or class is anonymous.
12331233
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified token is not of type
12341234
* T_FUNCTION, T_CLASS, T_ANON_CLASS,
1235-
* T_CLOSURE, T_TRAIT, or T_INTERFACE.
1235+
* T_CLOSURE, T_TRAIT, T_ENUM, or T_INTERFACE.
12361236
*/
12371237
public function getDeclarationName($stackPtr)
12381238
{
@@ -1246,8 +1246,9 @@ public function getDeclarationName($stackPtr)
12461246
&& $tokenCode !== T_CLASS
12471247
&& $tokenCode !== T_INTERFACE
12481248
&& $tokenCode !== T_TRAIT
1249+
&& $tokenCode !== T_ENUM
12491250
) {
1250-
throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT');
1251+
throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM');
12511252
}
12521253

12531254
if ($tokenCode === T_FUNCTION

src/Standards/Generic/Sniffs/Classes/DuplicateClassNameSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function process(File $phpcsFile, $stackPtr)
5353
T_CLASS,
5454
T_INTERFACE,
5555
T_TRAIT,
56+
T_ENUM,
5657
T_NAMESPACE,
5758
T_CLOSE_TAG,
5859
];

src/Standards/Generic/Sniffs/Classes/OpeningBraceSameLineSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function register()
2727
T_CLASS,
2828
T_INTERFACE,
2929
T_TRAIT,
30+
T_ENUM,
3031
];
3132

3233
}//end register()

src/Standards/Generic/Sniffs/Files/OneObjectStructurePerFileSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function register()
2727
T_CLASS,
2828
T_INTERFACE,
2929
T_TRAIT,
30+
T_ENUM,
3031
];
3132

3233
}//end register()

src/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function register()
5050
T_ENDIF,
5151
T_ENDSWITCH,
5252
T_ENDWHILE,
53+
T_ENUM,
5354
T_EVAL,
5455
T_EXIT,
5556
T_EXTENDS,

src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.1.inc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ interface MyInterface {}
55
interface YourInterface {}
66
trait MyTrait {}
77
trait YourTrait {}
8+
enum MyEnum {}
9+
enum YourEnum {}
810
class MyClass {}
911
interface MyInterface {}
1012
trait MyTrait {}
11-
?>
13+
enum MyEnum {}
14+
?>

src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.2.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
class MyClass {}
33
interface MyInterface {}
44
trait MyTrait {}
5+
enum MyEnum {}
56
?>

src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,18 @@ public function getWarningList($testFile='')
4545
switch ($testFile) {
4646
case 'DuplicateClassNameUnitTest.1.inc':
4747
return [
48-
8 => 1,
49-
9 => 1,
5048
10 => 1,
49+
11 => 1,
50+
12 => 1,
51+
13 => 1,
5152
];
5253
break;
5354
case 'DuplicateClassNameUnitTest.2.inc':
5455
return [
5556
2 => 1,
5657
3 => 1,
5758
4 => 1,
59+
5 => 1,
5860
];
5961
break;
6062
case 'DuplicateClassNameUnitTest.5.inc':

src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,7 @@ class Test_Class_Bad_G
8989
/*some comment*/
9090
{
9191
}
92+
93+
enum Test_Enum
94+
{
95+
}

0 commit comments

Comments
 (0)