| @@ -19,8 +19,9 @@ | ||
| 19 | 19 | use PHP_CodeSniffer\Tokenizers\Tokenizer; |
| 20 | 20 | use PHP_CodeSniffer\Exceptions\RuntimeException; |
| 21 | 21 | use PHP_CodeSniffer\Exceptions\DeepExitException; |
| 22 | 22 | use PHP_CodeSniffer\Exceptions\TokenizerException; |
| 23 | +use WP_Filesystem_Base; | |
| 23 | 24 | |
| 24 | 25 | /** |
| 25 | 26 | * We need to verify the result to avoid false positive. |
| 26 | 27 | */ |
| @@ -38,9 +39,9 @@ | ||
| 38 | 39 | */ |
| 39 | 40 | public function do_deep_scan( $file, $quick_found ) { |
| 40 | 41 | global $wp_filesystem; |
| 41 | 42 | // Initialize the WP filesystem, no more using 'file-put-contents' function. |
| 42 | - if ( empty( $wp_filesystem ) ) { | |
| 43 | + if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { | |
| 43 | 44 | require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 44 | 45 | WP_Filesystem(); |
| 45 | 46 | } |
| 46 | 47 | $this->load_phpcodesniffer_needed(); |
| @@ -81,10 +82,13 @@ | ||
| 81 | 82 | ) ) { |
| 82 | 83 | unset( $tokens[ $k ] ); |
| 83 | 84 | } |
| 84 | 85 | } |
| 85 | - $tokens = array_filter( $tokens ); | |
| 86 | - if ( empty( $tokens ) ) { | |
| 86 | + $tokens = array_filter( | |
| 87 | + $tokens, | |
| 88 | + static fn( array $token ): bool => array() !== $token | |
| 89 | + ); | |
| 90 | + if ( array() === $tokens ) { | |
| 87 | 91 | // This mean the catch is comment, do nothing. |
| 88 | 92 | return false; |
| 89 | 93 | } |
| 90 | 94 | unset( $catch['text'] ); |