Skip to content

Commit c445c99

Browse files
committed
add tokenIsPhpstanComment() function
1 parent a150c02 commit c445c99

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ public function process(File $phpcsFile, $stackPtr)
9797

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

193191

192+
/**
193+
* Determine if a token is a '@phpstan-' control comment.
194+
*
195+
* @param array $token The token to be checked.
196+
*
197+
* @return bool True if the token contains a @phpstan comment.
198+
*/
199+
public static function tokenIsPhpstanComment($token)
200+
{
201+
return ($token['code'] === T_COMMENT && strpos($token['content'], ' @phpstan-') !== false);
202+
203+
}//end tokenIsPhpstanComment()
204+
205+
194206
/**
195207
* Process the return comment of this function comment.
196208
*

0 commit comments

Comments
 (0)