Skip to content

Commit 7beba37

Browse files
committed
PHP 8.1: PSR1/ClassDeclaration - Added support for enums
1 parent 6c96e55 commit 7beba37

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
11011101
<dir name="Classes">
11021102
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.1.inc" role="test" />
11031103
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.2.inc" role="test" />
1104+
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.3.inc" role="test" />
11041105
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.php" role="test" />
11051106
</dir>
11061107
<dir name="Files">

src/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php

Lines changed: 3 additions & 2 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()
@@ -50,7 +51,7 @@ public function process(File $phpcsFile, $stackPtr)
5051

5152
$errorData = [strtolower($tokens[$stackPtr]['content'])];
5253

53-
$nextClass = $phpcsFile->findNext([T_CLASS, T_INTERFACE, T_TRAIT], ($tokens[$stackPtr]['scope_closer'] + 1));
54+
$nextClass = $phpcsFile->findNext([T_CLASS, T_INTERFACE, T_TRAIT, T_ENUM], ($tokens[$stackPtr]['scope_closer'] + 1));
5455
if ($nextClass !== false) {
5556
$error = 'Each %s must be in a file by itself';
5657
$phpcsFile->addError($error, $nextClass, 'MultipleClasses', $errorData);
@@ -59,7 +60,7 @@ public function process(File $phpcsFile, $stackPtr)
5960
$phpcsFile->recordMetric($stackPtr, 'One class per file', 'yes');
6061
}
6162

62-
$namespace = $phpcsFile->findNext([T_NAMESPACE, T_CLASS, T_INTERFACE, T_TRAIT], 0);
63+
$namespace = $phpcsFile->findNext([T_NAMESPACE, T_CLASS, T_INTERFACE, T_TRAIT, T_ENUM], 0);
6364
if ($tokens[$namespace]['code'] !== T_NAMESPACE) {
6465
$error = 'Each %s must be in a namespace of at least one level (a top-level vendor name)';
6566
$phpcsFile->addError($error, $stackPtr, 'MissingNamespace', $errorData);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
class Foo {}
3+
enum Bar {}

0 commit comments

Comments
 (0)