Skip to content

Commit

Permalink
Fix wrong @param tag counting when a hook has no arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jan 11, 2022
1 parent e7dcf55 commit 449b1e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion WPForms/Sniffs/Comments/ParamTagHooksSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ private function countArguments( $phpcsFile, $stackPtr ) { // phpcs:ignore Gener
$tokens = $phpcsFile->getTokens();
$openParenthesis = $phpcsFile->findNext( [ T_OPEN_PARENTHESIS ], $stackPtr + 1 );
$lastPosition = $tokens[ $openParenthesis ]['parenthesis_closer'] - 1;
$currentPosition = $phpcsFile->findNext( T_COMMA, $stackPtr + 1 ) + 1;
$commaPtr = $phpcsFile->findNext( T_COMMA, $stackPtr + 1 );

if ( $commaPtr === false ) {
return 0;
}

$currentPosition = $commaPtr + 1;
$quantity = 0;

while ( $currentPosition < $lastPosition ) {
Expand Down
3 changes: 3 additions & 0 deletions WPForms/Tests/TestFiles/Comments/ParamTagHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,6 @@ function () {

/** This action is documented in some-class.php. */
do_action( 'wpforms_display_submit_after', $this->displaysubmit_after_action );

// This case generated 'You should have 39 @param tags' (39 as an example).
do_action( 'hook_without_args' );

0 comments on commit 449b1e2

Please sign in to comment.