Skip to content

Commit 0620684

Browse files
committed
NamingConventions/ValidFunctionName: add tests using readonly anonymous classes
This commit adds a few tests using readonly anonymous classes to the `WordPress.NamingConventions.ValidFunctionName` tests. This is just to ensure that the part of the sniff code that checks for `T_ANON_CLASS` tokens works correctly with readonly anonymous class added in PHP 8.3. The sniff was already handling readonly anonymous classes correctly, and no change to the sniff code is needed.
1 parent 328d702 commit 0620684

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.1.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,12 @@ enum Suit {
222222
function lähtöaika() {} // OK.
223223
function lÄhtÖaika() {} // Bad, but only handled by the sniff if Mbstring is available.
224224
function lÄhtOaika() {} // Bad, handled via transliteration of non-ASCII chars if Mbstring is not available.
225+
226+
/*
227+
* Safeguard that PHP 8.3+ readonly anonymous classes are handled correctly.
228+
*/
229+
$anon_class = new readonly class() {
230+
public function camelCase() {} // Bad.
231+
protected function __something() {} // Bad.
232+
private function snake_case() {} // Ok.
233+
};

WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public function getErrorList( $testFile = '' ) {
6060
210 => 1,
6161
223 => function_exists( 'mb_strtolower' ) ? 1 : 0,
6262
224 => 1,
63+
230 => 1,
64+
231 => 1,
6365
);
6466

6567
default:

0 commit comments

Comments
 (0)