Skip to content

Commit

Permalink
Commenting/TestsHaveCoversTag: minor tweaks
Browse files Browse the repository at this point in the history
* Remove an unnecessary condition.
* Remove a `return` which will never receive a value to return.
* Bow out earlier if something useful was found. No need to continue examining.
* Minor doc updates for future reference.
  • Loading branch information
jrfnl committed Nov 4, 2023
1 parent 4230545 commit 6b213b6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Yoast/Sniffs/Commenting/TestsHaveCoversTagSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ public function process( File $phpcsFile, $stackPtr ) {
return $this->process_class( $phpcsFile, $stackPtr );
}

if ( $tokens[ $stackPtr ]['code'] === \T_FUNCTION ) {
return $this->process_function( $phpcsFile, $stackPtr );
}
// This must be a T_FUNCTION token.
$this->process_function( $phpcsFile, $stackPtr );
}

/**
Expand Down Expand Up @@ -78,7 +77,7 @@ private function process_class( File $phpcsFile, $stackPtr ) {
return;
}

// @todo: Once PHPCSUtils is out, replace with call to new findCommentAboveOOStructure() method.
// @todo: Once PHPCSUtils 1.2.0 (?) is out, replace with call to new findCommentAboveOOStructure() method.
$ignore = [
\T_WHITESPACE => \T_WHITESPACE,
\T_ABSTRACT => \T_ABSTRACT,
Expand Down Expand Up @@ -113,10 +112,12 @@ private function process_class( File $phpcsFile, $stackPtr ) {
foreach ( $tokens[ $commentStart ]['comment_tags'] as $tag ) {
if ( $tokens[ $tag ]['content'] === '@covers' ) {
$foundCovers = true;
break;
}

if ( $tokens[ $tag ]['content'] === '@coversNothing' ) {
$foundCoversNothing = true;
break;
}
}

Expand Down Expand Up @@ -144,7 +145,7 @@ private function process_function( File $phpcsFile, $stackPtr ) {
return;
}

// @todo: Once PHPCSUtils is out, replace with call to new findCommentAboveFunction() method.
// @todo: Once PHPCSUtils 1.2.0 (?) is out, replace with call to new findCommentAboveFunction() method.
$ignore = Tokens::$methodPrefixes;
$ignore[ \T_WHITESPACE ] = \T_WHITESPACE;

Expand Down

0 comments on commit 6b213b6

Please sign in to comment.