Skip to content

Commit e60f9a1

Browse files
committed
Merge branch 'inline-if-condition' of https://github.com/aboks/PHP_CodeSniffer
2 parents 62a2489 + b2f4e66 commit e60f9a1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Standards/Squiz/Sniffs/Operators/ComparisonOperatorUsageSniff.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,16 @@ public function process(File $phpcsFile, $stackPtr)
116116
if (isset($tokens[$i]['scope_closer']) === true) {
117117
break;
118118
}
119-
}
119+
} else if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS) {
120+
// Stop if this is the start of a pair of
121+
// parentheses that surrounds the inline
122+
// IF statement.
123+
if (isset($tokens[$i]['parenthesis_closer']) === true
124+
&& $tokens[$i]['parenthesis_closer'] >= $stackPtr
125+
) {
126+
break;
127+
}
128+
}//end if
120129
}//end for
121130

122131
$start = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);

src/Standards/Squiz/Tests/Operators/ComparisonOperatorUsageUnitTest.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,5 @@ function foo(string $bar, array $baz, ?MyClass $object) : MyClass {}
134134

135135
if (empty($argTags > 0)) {
136136
}
137+
138+
myFunction($var1 === true ? "" : "foobar");

0 commit comments

Comments
 (0)