From 9c878769a86e84ff23b5792e0e80ecde418f39fb Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 30 Jun 2023 01:36:02 +0200 Subject: [PATCH 1/3] Files/FileName: improve handling of files using non-underscore, non-dash word separators Addresses Gary's question in 2154: > I can see there are some test files with extra `.` in (and not just underscores), but I was wondering if an incorrect file name like `class.my-class.php` might be detected, as the checking for hyphenation only replaces underscores. I have tested this and while the file would already be flagged by the "class name vs file name check", the "is hyphenated" check would not flag the file. Fixed now. Includes extra tests. Note: this fix requires that the numbered test files we were using have to be renamed as the `.#.inc` would cause the sniff to throw errors when there shouldn't be any. Related to issue 2164, but doesn't fix it completely. --- WordPress/Sniffs/Files/FileNameSniff.php | 9 +++-- WordPress/Tests/Files/FileNameUnitTest.php | 34 ++++++++++--------- ...it.1.inc => test-sample-custom-unit-1.inc} | 0 ...it.2.inc => test-sample-custom-unit-2.inc} | 0 ...it.3.inc => test-sample-custom-unit-3.inc} | 0 ...it.4.inc => test-sample-custom-unit-4.inc} | 0 ...it.5.inc => test-sample-custom-unit-5.inc} | 0 ...est-sample-global-namespace-extends-1.inc} | 0 ...est-sample-global-namespace-extends-2.inc} | 0 ... test-sample-namespaced-declaration-1.inc} | 0 ... test-sample-namespaced-declaration-2.inc} | 0 ... test-sample-namespaced-declaration-3.inc} | 0 ... test-sample-namespaced-declaration-4.inc} | 0 ...c => test-sample-namespaced-extends-1.inc} | 0 ...c => test-sample-namespaced-extends-2.inc} | 0 ...c => test-sample-namespaced-extends-3.inc} | 0 ...c => test-sample-namespaced-extends-4.inc} | 0 ...c => test-sample-namespaced-extends-5.inc} | 0 .../class.with.dot.not.underscore.inc | 3 ++ .../class@with#other+punctuation.inc | 3 ++ 20 files changed, 31 insertions(+), 18 deletions(-) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-custom-unit.1.inc => test-sample-custom-unit-1.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-custom-unit.2.inc => test-sample-custom-unit-2.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-custom-unit.3.inc => test-sample-custom-unit-3.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-custom-unit.4.inc => test-sample-custom-unit-4.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-custom-unit.5.inc => test-sample-custom-unit-5.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-global-namespace-extends.1.inc => test-sample-global-namespace-extends-1.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-global-namespace-extends.2.inc => test-sample-global-namespace-extends-2.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-namespaced-declaration.1.inc => test-sample-namespaced-declaration-1.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-namespaced-declaration.2.inc => test-sample-namespaced-declaration-2.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-namespaced-declaration.3.inc => test-sample-namespaced-declaration-3.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-namespaced-declaration.4.inc => test-sample-namespaced-declaration-4.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-namespaced-extends.1.inc => test-sample-namespaced-extends-1.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-namespaced-extends.2.inc => test-sample-namespaced-extends-2.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-namespaced-extends.3.inc => test-sample-namespaced-extends-3.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-namespaced-extends.4.inc => test-sample-namespaced-extends-4.inc} (100%) rename WordPress/Tests/Files/FileNameUnitTests/TestFiles/{test-sample-namespaced-extends.5.inc => test-sample-namespaced-extends-5.inc} (100%) create mode 100644 WordPress/Tests/Files/FileNameUnitTests/class.with.dot.not.underscore.inc create mode 100644 WordPress/Tests/Files/FileNameUnitTests/class@with#other+punctuation.inc diff --git a/WordPress/Sniffs/Files/FileNameSniff.php b/WordPress/Sniffs/Files/FileNameSniff.php index e69472572c..d8b1bc5370 100644 --- a/WordPress/Sniffs/Files/FileNameSniff.php +++ b/WordPress/Sniffs/Files/FileNameSniff.php @@ -207,8 +207,13 @@ public function process_token( $stackPtr ) { * @return void */ protected function check_filename_is_hyphenated( $file_name ) { - $expected = strtolower( str_replace( '_', '-', $file_name ) ); - if ( $file_name === $expected ) { + $extension = strrchr( $file_name, '.' ); + $name = substr( $file_name, 0, ( strlen( $file_name ) - strlen( $extension ) ) ); + + $expected = strtolower( preg_replace( '`[[:punct:]]`', '-', $name ) ) . $extension; + if ( $file_name === $expected + || isset( $this->class_exceptions[ $file_name ] ) + ) { return; } diff --git a/WordPress/Tests/Files/FileNameUnitTest.php b/WordPress/Tests/Files/FileNameUnitTest.php index 0e8c48579f..5abba579cc 100644 --- a/WordPress/Tests/Files/FileNameUnitTest.php +++ b/WordPress/Tests/Files/FileNameUnitTest.php @@ -40,6 +40,8 @@ final class FileNameUnitTest extends AbstractSniffUnitTest { 'SomeFile.inc' => 1, 'some-File.inc' => 1, 'SomeView.inc' => 1, + 'class.with.dot.not.underscore.inc' => 2, + 'class@with#other+punctuation.inc' => 2, // Class file names. 'my-class.inc' => 1, @@ -75,23 +77,23 @@ final class FileNameUnitTest extends AbstractSniffUnitTest { 'test-sample-phpunit.inc' => 0, 'test-sample-phpunit6.inc' => 0, 'test-sample-wpunit.inc' => 0, - 'test-sample-custom-unit.1.inc' => 0, - 'test-sample-custom-unit.2.inc' => 0, - 'test-sample-custom-unit.3.inc' => 0, - 'test-sample-custom-unit.4.inc' => 0, - 'test-sample-custom-unit.5.inc' => 1, // Namespaced vs non-namespaced. - 'test-sample-namespaced-declaration.1.inc' => 0, - 'test-sample-namespaced-declaration.2.inc' => 1, // Namespaced vs non-namespaced. - 'test-sample-namespaced-declaration.3.inc' => 1, // Wrong namespace. - 'test-sample-namespaced-declaration.4.inc' => 1, // Non-namespaced vs namespaced. - 'test-sample-global-namespace-extends.1.inc' => 0, // Prefixed user input. - 'test-sample-global-namespace-extends.2.inc' => 1, // Non-namespaced vs namespaced. + 'test-sample-custom-unit-1.inc' => 0, + 'test-sample-custom-unit-2.inc' => 0, + 'test-sample-custom-unit-3.inc' => 0, + 'test-sample-custom-unit-4.inc' => 0, + 'test-sample-custom-unit-5.inc' => 1, // Namespaced vs non-namespaced. + 'test-sample-namespaced-declaration-1.inc' => 0, + 'test-sample-namespaced-declaration-2.inc' => 1, // Namespaced vs non-namespaced. + 'test-sample-namespaced-declaration-3.inc' => 1, // Wrong namespace. + 'test-sample-namespaced-declaration-4.inc' => 1, // Non-namespaced vs namespaced. + 'test-sample-global-namespace-extends-1.inc' => 0, // Prefixed user input. + 'test-sample-global-namespace-extends-2.inc' => 1, // Non-namespaced vs namespaced. 'test-sample-extends-with-use.inc' => 0, - 'test-sample-namespaced-extends.1.inc' => 0, - 'test-sample-namespaced-extends.2.inc' => 1, // Wrong namespace. - 'test-sample-namespaced-extends.3.inc' => 1, // Namespaced vs non-namespaced. - 'test-sample-namespaced-extends.4.inc' => 1, // Non-namespaced vs namespaced. - 'test-sample-namespaced-extends.5.inc' => 0, + 'test-sample-namespaced-extends-1.inc' => 0, + 'test-sample-namespaced-extends-2.inc' => 1, // Wrong namespace. + 'test-sample-namespaced-extends-3.inc' => 1, // Namespaced vs non-namespaced. + 'test-sample-namespaced-extends-4.inc' => 1, // Non-namespaced vs namespaced. + 'test-sample-namespaced-extends-5.inc' => 0, 'Test_Sample.inc' => 0, /* diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit.1.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit-1.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit.1.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit-1.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit.2.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit-2.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit.2.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit-2.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit.3.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit-3.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit.3.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit-3.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit.4.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit-4.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit.4.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit-4.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit.5.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit-5.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit.5.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-custom-unit-5.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-global-namespace-extends.1.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-global-namespace-extends-1.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-global-namespace-extends.1.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-global-namespace-extends-1.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-global-namespace-extends.2.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-global-namespace-extends-2.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-global-namespace-extends.2.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-global-namespace-extends-2.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration.1.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration-1.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration.1.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration-1.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration.2.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration-2.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration.2.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration-2.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration.3.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration-3.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration.3.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration-3.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration.4.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration-4.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration.4.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-declaration-4.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.1.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends-1.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.1.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends-1.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.2.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends-2.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.2.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends-2.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.3.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends-3.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.3.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends-3.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.4.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends-4.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.4.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends-4.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.5.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends-5.inc similarity index 100% rename from WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.5.inc rename to WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends-5.inc diff --git a/WordPress/Tests/Files/FileNameUnitTests/class.with.dot.not.underscore.inc b/WordPress/Tests/Files/FileNameUnitTests/class.with.dot.not.underscore.inc new file mode 100644 index 0000000000..9bbdfa79fe --- /dev/null +++ b/WordPress/Tests/Files/FileNameUnitTests/class.with.dot.not.underscore.inc @@ -0,0 +1,3 @@ + Date: Fri, 30 Jun 2023 02:28:18 +0200 Subject: [PATCH 2/3] Files/FileName: improve handling of files using different file extensions Addresses Gary's second question in 2154: > I also see `substr( $file_name, 0, -4 )`, which is assuming that a PHP-rendered file will always have a three letter file extension, but I wonder if someone could break that assumption with `--extensions=php3,myphp` or similar. While I still think we should add a rule about requiring the `.php` extension to the handbook (after a Make post), as that rule currently doesn't exist, the sniff should not assume that all files will have a three character file extension. Fixed now. Includes extra tests. Related to issue 2164, but doesn't fix it completely. (the "check for a `.php` file extension" is not addressed yet as this is not a handbook rule at this time) --- WordPress/Sniffs/Files/FileNameSniff.php | 7 ++++--- WordPress/Tests/Files/FileNameUnitTest.php | 6 ++++++ .../class-file-with-different-extension.php3 | 3 +++ .../class-wrong-with-different-extension.php3 | 3 +++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 WordPress/Tests/Files/FileNameUnitTests/class-file-with-different-extension.php3 create mode 100644 WordPress/Tests/Files/FileNameUnitTests/class-wrong-with-different-extension.php3 diff --git a/WordPress/Sniffs/Files/FileNameSniff.php b/WordPress/Sniffs/Files/FileNameSniff.php index d8b1bc5370..5fed8e77ec 100644 --- a/WordPress/Sniffs/Files/FileNameSniff.php +++ b/WordPress/Sniffs/Files/FileNameSniff.php @@ -242,10 +242,11 @@ protected function check_filename_is_hyphenated( $file_name ) { * @return void */ protected function check_filename_has_class_prefix( $class_ptr, $file_name ) { + $extension = strrchr( $file_name, '.' ); $class_name = ObjectDeclarations::getName( $this->phpcsFile, $class_ptr ); - $expected = 'class-' . strtolower( str_replace( '_', '-', $class_name ) ); + $expected = 'class-' . strtolower( str_replace( '_', '-', $class_name ) ) . $extension; - if ( substr( $file_name, 0, -4 ) === $expected + if ( $file_name === $expected || isset( $this->class_exceptions[ $file_name ] ) ) { return; @@ -256,7 +257,7 @@ protected function check_filename_has_class_prefix( $class_ptr, $file_name ) { 0, 'InvalidClassFileName', array( - $expected . '.php', + $expected, $file_name, ) ); diff --git a/WordPress/Tests/Files/FileNameUnitTest.php b/WordPress/Tests/Files/FileNameUnitTest.php index 5abba579cc..e1cf277cb2 100644 --- a/WordPress/Tests/Files/FileNameUnitTest.php +++ b/WordPress/Tests/Files/FileNameUnitTest.php @@ -42,6 +42,7 @@ final class FileNameUnitTest extends AbstractSniffUnitTest { 'SomeView.inc' => 1, 'class.with.dot.not.underscore.inc' => 2, 'class@with#other+punctuation.inc' => 2, + 'class-wrong-with-different-extension.php3' => 1, // Class file names. 'my-class.inc' => 1, @@ -132,6 +133,11 @@ protected function getTestFiles( $testFileBase ) { $sep = \DIRECTORY_SEPARATOR; $test_files = glob( dirname( $testFileBase ) . $sep . 'FileNameUnitTests{' . $sep . ',' . $sep . '*' . $sep . '}*.inc', \GLOB_BRACE ); + $php3_test_files = glob( dirname( $testFileBase ) . $sep . 'FileNameUnitTests{' . $sep . ',' . $sep . '*' . $sep . '}*.php3', \GLOB_BRACE ); + foreach ( $php3_test_files as $file ) { + $test_files[] = $file; + } + if ( ! empty( $test_files ) ) { return $test_files; } diff --git a/WordPress/Tests/Files/FileNameUnitTests/class-file-with-different-extension.php3 b/WordPress/Tests/Files/FileNameUnitTests/class-file-with-different-extension.php3 new file mode 100644 index 0000000000..ad920b4cab --- /dev/null +++ b/WordPress/Tests/Files/FileNameUnitTests/class-file-with-different-extension.php3 @@ -0,0 +1,3 @@ + Date: Sat, 1 Jul 2023 22:12:17 +0200 Subject: [PATCH 3/3] Files/FileName: update for changes in WP Core In WP 6.1.0, the classes contained in the files listed in `$class_exceptions` were moved to files which comply with the file name requirements. The original files still remain, but no longer contain a class, so we no longer need to make an exception for these in the `check_filename_has_class_prefix()` check. However, with the stricter check for hyphenation-only word separators as introduced in the earlier commit, we do need to continue making an exception for these files for the `check_filename_is_hyphenated()` check. For that reason, the properties remain. Having said that, in this commit: * I remove the check against these properties from the `check_filename_has_class_prefix()` check. * The properties are renamed to `$*hyphenation_exceptions` to better reflect what they are used for. * Two additional non-compliant files from WP Core are added to the list. --- WordPress/Sniffs/Files/FileNameSniff.php | 24 +++++++++++++------ .../class.wp-dependencies.inc | 2 +- .../FileNameUnitTests/class.wp-scripts.inc | 2 +- .../FileNameUnitTests/class.wp-styles.inc | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/WordPress/Sniffs/Files/FileNameSniff.php b/WordPress/Sniffs/Files/FileNameSniff.php index 5fed8e77ec..4178599dcd 100644 --- a/WordPress/Sniffs/Files/FileNameSniff.php +++ b/WordPress/Sniffs/Files/FileNameSniff.php @@ -96,27 +96,39 @@ final class FileNameSniff extends Sniff { /** * Historical exceptions in WP core to the class name rule. * + * Note: these files were renamed to comply with the naming conventions in + * WP 6.1.0. + * This means we no longer need to make an exception for them in the + * `check_filename_has_class_prefix()` check, however, we do still need to + * make an exception in the `check_filename_is_hyphenated()` check. + * * @since 0.11.0 + * @since 3.0.0 Property has been renamed from `$class_exceptions` to `$hyphenation_exceptions`, * * @var array */ - private $class_exceptions = array( + private $hyphenation_exceptions = array( 'class.wp-dependencies.php' => true, 'class.wp-scripts.php' => true, 'class.wp-styles.php' => true, + 'functions.wp-scripts.php' => true, + 'functions.wp-styles.php' => true, ); /** * Unit test version of the historical exceptions in WP core. * * @since 0.11.0 + * @since 3.0.0 Property has been renamed from `$unittest_class_exceptions` to `$unittest_hyphenation_exceptions`, * * @var array */ - private $unittest_class_exceptions = array( + private $unittest_hyphenation_exceptions = array( 'class.wp-dependencies.inc' => true, 'class.wp-scripts.inc' => true, 'class.wp-styles.inc' => true, + 'functions.wp-scripts.inc' => true, + 'functions.wp-styles.inc' => true, ); /** @@ -126,7 +138,7 @@ final class FileNameSniff extends Sniff { */ public function register() { if ( \defined( '\PHP_CODESNIFFER_IN_TESTS' ) ) { - $this->class_exceptions += $this->unittest_class_exceptions; + $this->hyphenation_exceptions += $this->unittest_hyphenation_exceptions; } return Collections::phpOpenTags(); @@ -212,7 +224,7 @@ protected function check_filename_is_hyphenated( $file_name ) { $expected = strtolower( preg_replace( '`[[:punct:]]`', '-', $name ) ) . $extension; if ( $file_name === $expected - || isset( $this->class_exceptions[ $file_name ] ) + || isset( $this->hyphenation_exceptions[ $file_name ] ) ) { return; } @@ -246,9 +258,7 @@ protected function check_filename_has_class_prefix( $class_ptr, $file_name ) { $class_name = ObjectDeclarations::getName( $this->phpcsFile, $class_ptr ); $expected = 'class-' . strtolower( str_replace( '_', '-', $class_name ) ) . $extension; - if ( $file_name === $expected - || isset( $this->class_exceptions[ $file_name ] ) - ) { + if ( $file_name === $expected ) { return; } diff --git a/WordPress/Tests/Files/FileNameUnitTests/class.wp-dependencies.inc b/WordPress/Tests/Files/FileNameUnitTests/class.wp-dependencies.inc index 021a2ea049..e2d041f055 100644 --- a/WordPress/Tests/Files/FileNameUnitTests/class.wp-dependencies.inc +++ b/WordPress/Tests/Files/FileNameUnitTests/class.wp-dependencies.inc @@ -1,3 +1,3 @@