Skip to content

Commit f09cf09

Browse files
committed
Files/FileName: start using the PHPCSUtils FilePath utility
The `FilePath::getName()` method will strip quotes from the file name, as well as normalize the slashes to forward (*nix) slashes. This allows for a minor simplication in the code and improves code readability.
1 parent a858fc9 commit f09cf09

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

WordPress/Sniffs/Files/FileNameSniff.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
namespace WordPressCS\WordPress\Sniffs\Files;
1111

1212
use PHPCSUtils\Tokens\Collections;
13+
use PHPCSUtils\Utils\FilePath;
1314
use PHPCSUtils\Utils\ObjectDeclarations;
14-
use PHPCSUtils\Utils\TextStrings;
1515
use WordPressCS\WordPress\Helpers\IsUnitTestTrait;
1616
use WordPressCS\WordPress\Sniff;
1717

@@ -151,8 +151,7 @@ public function register() {
151151
* normal file processing.
152152
*/
153153
public function process_token( $stackPtr ) {
154-
// Usage of `stripQuotes` is to ensure `stdin_path` passed by IDEs does not include quotes.
155-
$file = TextStrings::stripQuotes( $this->phpcsFile->getFileName() );
154+
$file = FilePath::getName( $this->phpcsFile );
156155
if ( 'STDIN' === $file ) {
157156
return $this->phpcsFile->numTokens;
158157
}
@@ -197,7 +196,7 @@ public function process_token( $stackPtr ) {
197196
$this->check_filename_has_class_prefix( $class_ptr, $file_name );
198197
}
199198

200-
if ( false !== strpos( $file, \DIRECTORY_SEPARATOR . 'wp-includes' . \DIRECTORY_SEPARATOR )
199+
if ( false !== strpos( $file, '/wp-includes/' )
201200
&& false === $class_ptr
202201
) {
203202
$this->check_filename_for_template_suffix( $stackPtr, $file_name );

0 commit comments

Comments
 (0)