From d59dcf675695c8e2d63e1c16ef052705fa34095b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 14 Oct 2023 07:09:54 +0200 Subject: [PATCH] Commenting/TestsHaveCoversTag: minor tweaks * 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. --- Yoast/Sniffs/Commenting/TestsHaveCoversTagSniff.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Yoast/Sniffs/Commenting/TestsHaveCoversTagSniff.php b/Yoast/Sniffs/Commenting/TestsHaveCoversTagSniff.php index 2822048b..2858bb0d 100644 --- a/Yoast/Sniffs/Commenting/TestsHaveCoversTagSniff.php +++ b/Yoast/Sniffs/Commenting/TestsHaveCoversTagSniff.php @@ -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 ); } /** @@ -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, @@ -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; } } @@ -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;