Skip to content

Commit 449b1e2

Browse files
committed
Fix wrong @param tag counting when a hook has no arguments.
1 parent e7dcf55 commit 449b1e2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

WPForms/Sniffs/Comments/ParamTagHooksSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ private function countArguments( $phpcsFile, $stackPtr ) { // phpcs:ignore Gener
112112
$tokens = $phpcsFile->getTokens();
113113
$openParenthesis = $phpcsFile->findNext( [ T_OPEN_PARENTHESIS ], $stackPtr + 1 );
114114
$lastPosition = $tokens[ $openParenthesis ]['parenthesis_closer'] - 1;
115-
$currentPosition = $phpcsFile->findNext( T_COMMA, $stackPtr + 1 ) + 1;
115+
$commaPtr = $phpcsFile->findNext( T_COMMA, $stackPtr + 1 );
116+
117+
if ( $commaPtr === false ) {
118+
return 0;
119+
}
120+
121+
$currentPosition = $commaPtr + 1;
116122
$quantity = 0;
117123

118124
while ( $currentPosition < $lastPosition ) {

WPForms/Tests/TestFiles/Comments/ParamTagHooks.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,6 @@ function () {
180180

181181
/** This action is documented in some-class.php. */
182182
do_action( 'wpforms_display_submit_after', $this->displaysubmit_after_action );
183+
184+
// This case generated 'You should have 39 @param tags' (39 as an example).
185+
do_action( 'hook_without_args' );

0 commit comments

Comments
 (0)