Skip to content

Commit

Permalink
Merge pull request #783 from Automattic/fix/alwaysreturninfilter-remo…
Browse files Browse the repository at this point in the history
…ve-redundant-condition
  • Loading branch information
GaryJones authored Aug 25, 2023
2 parents 211e718 + 92fdfd2 commit 5f34bbe
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions WordPressVIPMinimum/Sniffs/Hooks/AlwaysReturnInFilterSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,10 @@ private function processFunctionBody( $stackPtr ) {
$functionBodyScopeEnd
);

$insideIfConditionalReturn = 0;
$outsideConditionalReturn = 0;
$outsideConditionalReturn = 0;

while ( $returnTokenPtr ) {
if ( $this->isInsideIfConditonal( $returnTokenPtr ) ) {
++$insideIfConditionalReturn;
} else {
if ( $this->isInsideIfConditonal( $returnTokenPtr ) === false ) {
++$outsideConditionalReturn;
}
if ( $this->isReturningVoid( $returnTokenPtr ) ) {
Expand All @@ -244,11 +241,10 @@ private function processFunctionBody( $stackPtr ) {
);
}

if ( $insideIfConditionalReturn >= 0 && $outsideConditionalReturn === 0 ) {
if ( $outsideConditionalReturn === 0 ) {
$message = 'Please, make sure that a callback to `%s` filter is always returning some value.';
$data = [ $filterName ];
$this->phpcsFile->addError( $message, $functionBodyScopeStart, 'MissingReturnStatement', $data );

}
}

Expand Down

0 comments on commit 5f34bbe

Please sign in to comment.