Skip to content

Commit 5f34bbe

Browse files
authored
Merge pull request #783 from Automattic/fix/alwaysreturninfilter-remove-redundant-condition
2 parents 211e718 + 92fdfd2 commit 5f34bbe

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

WordPressVIPMinimum/Sniffs/Hooks/AlwaysReturnInFilterSniff.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,10 @@ private function processFunctionBody( $stackPtr ) {
223223
$functionBodyScopeEnd
224224
);
225225

226-
$insideIfConditionalReturn = 0;
227-
$outsideConditionalReturn = 0;
226+
$outsideConditionalReturn = 0;
228227

229228
while ( $returnTokenPtr ) {
230-
if ( $this->isInsideIfConditonal( $returnTokenPtr ) ) {
231-
++$insideIfConditionalReturn;
232-
} else {
229+
if ( $this->isInsideIfConditonal( $returnTokenPtr ) === false ) {
233230
++$outsideConditionalReturn;
234231
}
235232
if ( $this->isReturningVoid( $returnTokenPtr ) ) {
@@ -244,11 +241,10 @@ private function processFunctionBody( $stackPtr ) {
244241
);
245242
}
246243

247-
if ( $insideIfConditionalReturn >= 0 && $outsideConditionalReturn === 0 ) {
244+
if ( $outsideConditionalReturn === 0 ) {
248245
$message = 'Please, make sure that a callback to `%s` filter is always returning some value.';
249246
$data = [ $filterName ];
250247
$this->phpcsFile->addError( $message, $functionBodyScopeStart, 'MissingReturnStatement', $data );
251-
252248
}
253249
}
254250

0 commit comments

Comments
 (0)