From f6f5157c305166f53121d6ff20b3398ffa8c5a98 Mon Sep 17 00:00:00 2001 From: Ramon Date: Thu, 1 Oct 2026 12:33:33 +1000 Subject: [PATCH] Coding standards: Skip anonymous class methods in the block library function name sniff The ValidBlockLibraryFunctionName sniff skips methods in classes, interfaces and traits, but anonymous classes use their own token (T_ANON_CLASS), so their methods were checked as if they were global functions. --- .../ValidBlockLibraryFunctionNameSniff.php | 1 + .../Tests/fixtures/block-library/src/my-block/index.inc | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/NamingConventions/ValidBlockLibraryFunctionNameSniff.php b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/NamingConventions/ValidBlockLibraryFunctionNameSniff.php index b23cdcfc665c0e..cc3e65a357216f 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/NamingConventions/ValidBlockLibraryFunctionNameSniff.php +++ b/test/php/gutenberg-coding-standards/Gutenberg/Sniffs/NamingConventions/ValidBlockLibraryFunctionNameSniff.php @@ -92,6 +92,7 @@ private function processFunctionToken( File $phpcsFile, $stackPointer ) { $wrapping_tokens_to_check = array( T_CLASS, + T_ANON_CLASS, T_INTERFACE, T_TRAIT, ); diff --git a/test/php/gutenberg-coding-standards/Gutenberg/Tests/fixtures/block-library/src/my-block/index.inc b/test/php/gutenberg-coding-standards/Gutenberg/Tests/fixtures/block-library/src/my-block/index.inc index 3f99eb9ca6b8e8..f5d91a651ae7c5 100644 --- a/test/php/gutenberg-coding-standards/Gutenberg/Tests/fixtures/block-library/src/my-block/index.inc +++ b/test/php/gutenberg-coding-standards/Gutenberg/Tests/fixtures/block-library/src/my-block/index.inc @@ -34,3 +34,9 @@ class MyClass { function foo() { } + +$object = new class() { + // Represents a non-prefixed method within an anonymous class. + public function some_non_prefixed_anonymous_class_method() { + } +};