Skip to content

Commit

Permalink
Fixed error with checking shorthand IF statements without a semicolon…
Browse files Browse the repository at this point in the history
… in Squiz InlineIfDeclarationSniff

git-svn-id: http://svn.php.net/repository/pear/packages/PHP_CodeSniffer/trunk@244212 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
gsherwood committed Oct 15, 2007
1 parent 1d876ec commit 835992f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,25 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

$statementEnd = $phpcsFile->findNext(array(T_SEMICOLON), ($stackPtr + 1), null, false);
// 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;
}
}

if ($i <= 0) {
// Could not find the begining of the statement, so we can't
// find the end either.
return;
}

$statementEnd = $tokens[$i]['parenthesis_closer'];

// Make sure it's all on the same line.
if ($tokens[$statementEnd]['line'] !== $tokens[$stackPtr]['line']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ echo 'var is '.(($var < 0) ? 'negative' : 'positive');
echo 'var is '.(($var < 0)
? 'negative'
: 'positive');

$args = array(
'"'.$this->id.'"',
'"'.$this->stepInfo['title'].'"',
'"'.((isset($this->stepInfo['description']) === TRUE) ? $this->stepInfo['description'] : '').'"',
'"'.(isset($this->stepInfo['description']) === TRUE ? $this->stepInfo['description'] : '').'"',
'"'.$this->stepInfo['title'].'"',
);
?>
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function getErrorList()
9 => 1,
10 => 1,
13 => 1,
20 => 1,
);

}//end getErrorList()
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Break statements must be followed by a blank line or the closing brace
-- There must be no blank line before a break statement
- Fixed error with multi-token array indexes in Squiz ArrayDeclarationSniff
- Fixed error with checking shorthand IF statements without a semicolon in Squiz InlineIfDeclarationSniff
- Fixed error where constants used as defulat values in function declarations were seen as type hints
</notes>
<contents>
Expand Down

0 comments on commit 835992f

Please sign in to comment.