Skip to content

Commit

Permalink
Added more guard code for syntax errors. Further fix for #316.
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Nov 11, 2014
1 parent 7aae771 commit 0e42098
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,18 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
return;
}

if (isset($tokens[$openBracket]['parenthesis_closer']) === false) {
return;
}

$closeBracket = $tokens[$openBracket]['parenthesis_closer'];

$nextSeparator = $openBracket;
while (($nextSeparator = $phpcsFile->findNext(T_VARIABLE, ($nextSeparator + 1), $closeBracket)) !== false) {
if (isset($tokens[$nextSeparator]['nested_parenthesis']) === false) {
continue;
}

// Make sure the variable belongs directly to this function call
// and is not inside a nested function call or array.
$brackets = $tokens[$nextSeparator]['nested_parenthesis'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose;
$tokens = $phpcsFile->getTokens();

if (isset($tokens[$stackPtr]['parenthesis_opener']) === true) {
if (isset($tokens[$stackPtr]['parenthesis_opener']) === true
&& isset($tokens[$stackPtr]['parenthesis_closer']) === true
) {
$parenOpener = $tokens[$stackPtr]['parenthesis_opener'];
$parenCloser = $tokens[$stackPtr]['parenthesis_closer'];
$spaceAfterOpen = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public function processOpen(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function processClose(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if (isset($tokens[$stackPtr]['scope_closer']) === false) {
return;
}

$closeBrace = $tokens[$stackPtr]['scope_closer'];
if ($tokens[($closeBrace - 1)]['code'] === T_WHITESPACE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

if (isset($tokens[$stackPtr]['parenthesis_opener']) === true) {
if (isset($tokens[$stackPtr]['parenthesis_opener']) === true
&& isset($tokens[$stackPtr]['parenthesis_closer']) === true
) {
$parenOpener = $tokens[$stackPtr]['parenthesis_opener'];
$parenCloser = $tokens[$stackPtr]['parenthesis_closer'];
if ($tokens[($parenOpener + 1)]['code'] === T_WHITESPACE) {
Expand Down

0 comments on commit 0e42098

Please sign in to comment.