Skip to content

Commit 32f3832

Browse files
jrfnlkukulich
authored andcommitted
Squiz/ValidClassName: improve enum tests + bugfix
Ensure that backed enum signatures are included in the tests. As this sniff retrieves the class name itself instead of using the `File::getDeclarationName()` method, these tests _will_ find the name correctly (not mistake the type for the name), but _may_ include the colon in the name as the "name end" determination checks on scope opener and whitespace and doesn't take the colon for the type declaration into account.
1 parent 7494c3d commit 32f3832

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function process(File $phpcsFile, $stackPtr)
5959
// starting with the number will be multiple tokens.
6060
$opener = $tokens[$stackPtr]['scope_opener'];
6161
$nameStart = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), $opener, true);
62-
$nameEnd = $phpcsFile->findNext(T_WHITESPACE, $nameStart, $opener);
62+
$nameEnd = $phpcsFile->findNext([T_WHITESPACE, T_COLON], $nameStart, $opener);
6363
if ($nameEnd === false) {
6464
$name = $tokens[$nameStart]['content'];
6565
} else {

src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ trait Base
138138
}
139139

140140
// Valid enum name.
141-
enum ValidCamelCaseClass {}
141+
enum ValidCamelCaseClass: string {}
142142

143143

144144
// Incorrect usage of camel case.
@@ -147,22 +147,22 @@ enum Invalid_Camel_Case_Class_With_Underscores {}
147147

148148

149149
// All lowercase.
150-
enum invalidlowercaseclass {}
150+
enum invalidlowercaseclass: INT {}
151151
enum invalid_lowercase_class_with_underscores {}
152152

153153

154154
// All uppercase.
155-
enum VALIDUPPERCASECLASS {}
155+
enum VALIDUPPERCASECLASS: int {}
156156
enum INVALID_UPPERCASE_CLASS_WITH_UNDERSCORES {}
157157

158158

159159
// Mix camel case with uppercase.
160-
enum ValidCamelCaseClassWithUPPERCASE {}
160+
enum ValidCamelCaseClassWithUPPERCASE : string {}
161161

162162

163163
// Usage of numeric characters.
164164
enum ValidCamelCaseClassWith1Number {}
165-
enum ValidCamelCaseClassWith12345Numbers {}
165+
enum ValidCamelCaseClassWith12345Numbers : string {}
166166
enum ValidCamelCaseClassEndingWithNumber5 {}
167167

168168
enum Testing{}

0 commit comments

Comments
 (0)