Skip to content

Commit 5511d78

Browse files
authored
Merge pull request #2547 from rodrigoprimo/typed-class-constants
2 parents e79ca2b + e14ab6a commit 5511d78

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ apply_filters( $_REQUEST['else'] ); // Warning.
276276

277277
class Acronym_Dynamic_Hooks {
278278
const FILTER = 'acronym';
279-
const FILTER_WITH_UNDERSCORE = 'acronym_';
279+
const ?string FILTER_WITH_UNDERSCORE = 'acronym_';
280280

281281
protected $filter = 'acronym';
282282
protected $filter_with_underscore = 'acronym_';

WordPress/Tests/WP/CapitalPDangitUnitTest.1.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,16 @@ echo Some\Enum\WordPress::ENUM_CONSTANT;
231231

232232
// Safeguard that the sniff doesn't act on anonymous classes.
233233
$anon = new class() {};
234+
235+
/*
236+
* Safeguard that PHP 8.3+ typed class constants are handled correctly (i.e. ignored).
237+
*/
238+
class TypeClassConstants {
239+
public const string WORDPRESS = 'wordress';
240+
241+
public const ?string ANOTHER = 'value',
242+
WORDPRESS_SOMETHING = 'wordpress';
243+
244+
// Ensures no false positives on incorrect casing in a class constant type name.
245+
public const (\Fully\Qualified\MyClass&wordPRESS)|string ANOTHER_WORDPRESS = 'wordpress';
246+
}

WordPress/Tests/WP/CapitalPDangitUnitTest.1.inc.fixed

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,16 @@ echo Some\Enum\WordPress::ENUM_CONSTANT;
231231

232232
// Safeguard that the sniff doesn't act on anonymous classes.
233233
$anon = new class() {};
234+
235+
/*
236+
* Safeguard that PHP 8.3+ typed class constants are handled correctly (i.e. ignored).
237+
*/
238+
class TypeClassConstants {
239+
public const string WORDPRESS = 'wordress';
240+
241+
public const ?string ANOTHER = 'value',
242+
WORDPRESS_SOMETHING = 'wordpress';
243+
244+
// Ensures no false positives on incorrect casing in a class constant type name.
245+
public const (\Fully\Qualified\MyClass&wordPRESS)|string ANOTHER_WORDPRESS = 'wordpress';
246+
}

0 commit comments

Comments
 (0)