Permalink
Browse files

Fixed bug #20213 : Invalid error, Inline IF must be declared on singl…

…e line
  • Loading branch information...
gsherwood committed Mar 6, 2014
1 parent 8505439 commit 50f38e862ca52b02c2487f236cdfa2a884e8f2a2
@@ -57,23 +57,23 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$tokens = $phpcsFile->getTokens();
// Find the opening bracket of the inline IF.
for ($i = ($stackPtr - 1); $i > 0; $i--) {
if (isset($tokens[$i]['parenthesis_opener']) === true
&& $tokens[$i]['parenthesis_opener'] < $i
) {
$i = $tokens[$i]['parenthesis_opener'];
continue;
}
if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS) {
break;
$i = 0;
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
$parens = $tokens[$stackPtr]['nested_parenthesis'];
$i = array_pop($parens);
if (isset($tokens[$i]['parenthesis_owner']) === true) {
// The parenthesis are owned by a token like an array or
// function, so are not just used for grouping.
$i = 0;
}
}
if ($i <= 0) {
// Could not find the beginning of the statement. Probably not
// wrapped with brackets, so assume it ends with a semicolon.
$statementEnd = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));
// wrapped with brackets, so assume it ends with a
// semicolon (end of statement) or comma (end of array value).
$else = $phpcsFile->findNext(T_INLINE_ELSE, ($stackPtr + 1));
$statementEnd = $phpcsFile->findNext(array(T_SEMICOLON, T_COMMA), ($else + 1));
} else {
$statementEnd = $tokens[$i]['parenthesis_closer'];
}
@@ -23,4 +23,9 @@ $args = array(
echo (TRUE)?'Hello':'Bye';
?>
$array = array(
'one' => ($test == 1) ? true : false,
'two' => (($test == 1) ? true : false),
);
$var = ($test == 1) ? true : false;
$var = (myFunc(1,2,3) == 1) ? true : false;
View
@@ -35,6 +35,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Maurus Cuelenaere for the patch
- Fixed bug #20200 : Invalid JSON produced with specific error message
- Fixed bug #20204 : Ruleset exclude checks are case sensitive
- Fixed bug #20213 : Invalid error, Inline IF must be declared on single line
</notes>
<contents>
<dir name="/">

0 comments on commit 50f38e8

Please sign in to comment.