Skip to content
Prev Previous commit
Next Next commit
add tokenIsPhpstanComment() function
  • Loading branch information
jonathan1055 committed May 18, 2025
commit c445c99116e43413b87a7d361cb1d5b33565e3f5
18 changes: 15 additions & 3 deletions coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ public function process(File $phpcsFile, $stackPtr)

// If there is a phpstan-ignore inline comment disregard it and continue searching backwards
// to find the function comment.
if ($tokens[$commentEnd]['code'] === T_COMMENT
&& preg_match('/\@phpstan-ignore/', $tokens[$commentEnd]['content']) === 1
) {
if ($this->tokenIsPhpstanComment($tokens[$commentEnd]) === true) {
$functionCodeStart = $commentEnd;
continue;
}
Expand Down Expand Up @@ -191,6 +189,20 @@ public function process(File $phpcsFile, $stackPtr)
}//end process()


/**
* Determine if a token is a '@phpstan-' control comment.
*
* @param array $token The token to be checked.
*
* @return bool True if the token contains a @phpstan comment.
*/
public static function tokenIsPhpstanComment($token)
{
return ($token['code'] === T_COMMENT && strpos($token['content'], ' @phpstan-') !== false);

}//end tokenIsPhpstanComment()


/**
* Process the return comment of this function comment.
*
Expand Down