Skip to content

Commit ed1e5a8

Browse files
committed
PHP 8.1: Squiz/ValidClassName - Added support for enums
1 parent 313d9db commit ed1e5a8

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

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

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

3334
}//end register()

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,50 @@ trait Base
137137
}
138138
}
139139

140+
// Valid enum name.
141+
enum ValidCamelCaseClass {}
142+
143+
144+
// Incorrect usage of camel case.
145+
enum invalidCamelCaseClass {}
146+
enum Invalid_Camel_Case_Class_With_Underscores {}
147+
148+
149+
// All lowercase.
150+
enum invalidlowercaseclass {}
151+
enum invalid_lowercase_class_with_underscores {}
152+
153+
154+
// All uppercase.
155+
enum VALIDUPPERCASECLASS {}
156+
enum INVALID_UPPERCASE_CLASS_WITH_UNDERSCORES {}
157+
158+
159+
// Mix camel case with uppercase.
160+
enum ValidCamelCaseClassWithUPPERCASE {}
161+
162+
163+
// Usage of numeric characters.
164+
enum ValidCamelCaseClassWith1Number {}
165+
enum ValidCamelCaseClassWith12345Numbers {}
166+
enum ValidCamelCaseClassEndingWithNumber5 {}
167+
168+
enum Testing{}
169+
170+
enum Base
171+
{
172+
public function __construct()
173+
{
174+
$this->anonymous = new class extends ArrayObject
175+
{
176+
public function __construct()
177+
{
178+
parent::__construct(['a' => 1, 'b' => 2]);
179+
}
180+
};
181+
}
182+
}
183+
140184
if ( class_exists( Test :: class ) ) {}
141185
if ( class_exists( Test2 ::class ) ) {}
142186

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public function getErrorList()
4747
108 => 1,
4848
118 => 1,
4949
120 => 1,
50+
145 => 1,
51+
146 => 1,
52+
150 => 1,
53+
151 => 1,
54+
156 => 1,
5055
];
5156

5257
}//end getErrorList()

0 commit comments

Comments
 (0)