Skip to content

Commit a4cc83c

Browse files
committed
Add skipping expressions in arguments.
1 parent 365002e commit a4cc83c

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

WPForms/Sniffs/Comments/ParamTagHooksSniff.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,17 @@ private function countArguments( $phpcsFile, $stackPtr ) { // phpcs:ignore Gener
119119

120120
$currentPosition = $commaPtr + 1;
121121
$quantity = 0;
122+
$lookingForComma = false;
122123

123124
while ( $currentPosition < $lastPosition ) {
124-
if ( in_array( $tokens[ $currentPosition ]['code'], [ T_WHITESPACE, T_COMMA ], true ) ) {
125+
if ( $tokens[ $currentPosition ]['code'] === T_WHITESPACE ) {
126+
$currentPosition ++;
127+
continue;
128+
}
129+
130+
if ( $tokens[ $currentPosition ]['code'] === T_COMMA ) {
131+
$lookingForComma = false;
132+
125133
$currentPosition ++;
126134
continue;
127135
}
@@ -134,13 +142,15 @@ private function countArguments( $phpcsFile, $stackPtr ) { // phpcs:ignore Gener
134142
continue;
135143
}
136144

137-
$quantity ++;
138-
139-
$currentPosition = $phpcsFile->findNext( [ T_COMMA, T_ARRAY, T_OPEN_SHORT_ARRAY, T_OPEN_PARENTHESIS, T_OPEN_SQUARE_BRACKET, T_OPEN_CURLY_BRACKET ], $currentPosition + 1 );
145+
$currentPosition ++;
140146

141-
if ( ! $currentPosition ) {
142-
break;
147+
if ( $lookingForComma ) {
148+
continue;
143149
}
150+
151+
$quantity ++;
152+
153+
$lookingForComma = true;
144154
}
145155

146156
return $quantity;

WPForms/Tests/TestFiles/Comments/ParamTagHooks.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ function () {
212212
/** This filter is documented in wp-includes/post-template.php */
213213
$content = apply_filters( 'the_content', $content );
214214

215+
// This filter counted args improperly due to presence of the function with parenthesis.
216+
215217
/**
216218
* Allow modifying the text or url for the full page on the AMP pages.
217219
*
@@ -235,3 +237,14 @@ function () {
235237
$full_page_url,
236238
$form_data
237239
);
240+
241+
// This filter counted args improperly due to expression in the argument.
242+
243+
/**
244+
* Allow filtering Rich Text field media cleanup window time.
245+
*
246+
* @since 1.7.0
247+
*
248+
* @param int $time Time.
249+
*/
250+
$time = (int) apply_filters( 'wpforms_richtext_override_auth_for_ajax_media_calls_time', time() + 1 * DAY_IN_SECONDS );

0 commit comments

Comments
 (0)