|
9 | 9 |
|
10 | 10 | namespace WordPressVIPMinimum\Sniffs\Functions; |
11 | 11 |
|
| 12 | +use PHPCSUtils\Utils\PassedParameters; |
12 | 13 | use WordPressCS\WordPress\AbstractFunctionParameterSniff; |
13 | 14 |
|
14 | 15 | /** |
@@ -43,16 +44,60 @@ class StripTagsSniff extends AbstractFunctionParameterSniff { |
43 | 44 | * in lowercase. |
44 | 45 | * @param array $parameters Array with information about the parameters. |
45 | 46 | * |
46 | | - * @return int|void Integer stack pointer to skip forward or void to continue |
47 | | - * normal file processing. |
| 47 | + * @return void |
48 | 48 | */ |
49 | 49 | public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) { |
50 | | - if ( count( $parameters ) === 1 ) { |
51 | | - $message = '`strip_tags()` does not strip CSS and JS in between the script and style tags. Use `wp_strip_all_tags()` to strip all tags.'; |
52 | | - $this->phpcsFile->addWarning( $message, $stackPtr, 'StripTagsOneParameter' ); |
53 | | - } elseif ( isset( $parameters[2] ) ) { |
| 50 | + $string_param = PassedParameters::getParameterFromStack( $parameters, 1, 'string' ); |
| 51 | + $allowed_tags_param = PassedParameters::getParameterFromStack( $parameters, 2, 'allowed_tags' ); |
| 52 | + |
| 53 | + if ( $string_param !== false && $allowed_tags_param === false ) { |
| 54 | + $this->add_warning( $stackPtr, 'StripTagsOneParameter' ); |
| 55 | + } elseif ( $allowed_tags_param !== false ) { |
54 | 56 | $message = '`strip_tags()` does not strip CSS and JS in between the script and style tags. Use `wp_kses()` instead to allow only the HTML you need.'; |
55 | 57 | $this->phpcsFile->addWarning( $message, $stackPtr, 'StripTagsTwoParameters' ); |
| 58 | + } else { |
| 59 | + $this->add_warning( $stackPtr ); |
56 | 60 | } |
57 | 61 | } |
| 62 | + |
| 63 | + /** |
| 64 | + * Process the function if no parameters were found. |
| 65 | + * |
| 66 | + * @param int $stackPtr The position of the current token in the stack. |
| 67 | + * @param string $group_name The name of the group which was matched. |
| 68 | + * @param string $matched_content The token content (function name) which was matched |
| 69 | + * in lowercase. |
| 70 | + * |
| 71 | + * @return void |
| 72 | + */ |
| 73 | + public function process_no_parameters( $stackPtr, $group_name, $matched_content ) { |
| 74 | + $this->add_warning( $stackPtr ); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Process the function if it is used as a first class callable. |
| 79 | + * |
| 80 | + * @param int $stackPtr The position of the current token in the stack. |
| 81 | + * @param string $group_name The name of the group which was matched. |
| 82 | + * @param string $matched_content The token content (function name) which was matched |
| 83 | + * in lowercase. |
| 84 | + * |
| 85 | + * @return void |
| 86 | + */ |
| 87 | + public function process_first_class_callable( $stackPtr, $group_name, $matched_content ) { |
| 88 | + $this->add_warning( $stackPtr ); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Add a warning if the function is used at all. |
| 93 | + * |
| 94 | + * @param int $stackPtr The position of the current token in the stack. |
| 95 | + * @param string $error_code Error code to use for the warning. |
| 96 | + * |
| 97 | + * @return void |
| 98 | + */ |
| 99 | + private function add_warning( $stackPtr, $error_code = 'Used' ) { |
| 100 | + $message = '`strip_tags()` does not strip CSS and JS in between the script and style tags. Use `wp_strip_all_tags()` to strip all tags.'; |
| 101 | + $this->phpcsFile->addWarning( $message, $stackPtr, $error_code ); |
| 102 | + } |
58 | 103 | } |
0 commit comments