| @@ -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 | */ |
| @@ -31,17 +32,16 @@ | ||
| 31 | 32 | /** |
| 32 | 33 | * Perform a deep scan on the provided file content to identify specific tokens. |
| 33 | 34 | * |
| 34 | 35 | * @param mixed $file The file content to be scanned. |
| 35 | - * @param array $rules The rules to be applied during scanning. | |
| 36 | 36 | * @param array $quick_found Array containing quick found items. |
| 37 | 37 | * |
| 38 | 38 | * @return array|bool Returns the array of quick found items after scanning or false if no tokens are found. |
| 39 | 39 | */ |
| 40 | - public function do_deep_scan( $file, $rules, $quick_found ) { | |
| 40 | + public function do_deep_scan( $file, $quick_found ) { | |
| 41 | 41 | global $wp_filesystem; |
| 42 | 42 | // Initialize the WP filesystem, no more using 'file-put-contents' function. |
| 43 | - if ( empty( $wp_filesystem ) ) { | |
| 43 | + if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { | |
| 44 | 44 | require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 45 | 45 | WP_Filesystem(); |
| 46 | 46 | } |
| 47 | 47 | $this->load_phpcodesniffer_needed(); |
| @@ -82,10 +82,13 @@ | ||
| 82 | 82 | ) ) { |
| 83 | 83 | unset( $tokens[ $k ] ); |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | - $tokens = array_filter( $tokens ); | |
| 87 | - if ( empty( $tokens ) ) { | |
| 86 | + $tokens = array_filter( | |
| 87 | + $tokens, | |
| 88 | + static fn( array $token ): bool => array() !== $token | |
| 89 | + ); | |
| 90 | + if ( array() === $tokens ) { | |
| 88 | 91 | // This mean the catch is comment, do nothing. |
| 89 | 92 | return false; |
| 90 | 93 | } |
| 91 | 94 | unset( $catch['text'] ); |