Skip to content

Commit

Permalink
Fixed bug #19726 : Wrong number of spaces expected after instanceof s…
Browse files Browse the repository at this point in the history
…tatic
  • Loading branch information
gsherwood committed Dec 3, 2012
1 parent 8f65b58 commit 2fc7017
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Expand Up @@ -31,4 +31,8 @@ abstract class Foo
return new static();
}
}
?>

if ($geometry instanceof static) {
echo 'foo';
}
?>
19 changes: 19 additions & 0 deletions CodeSniffer/Tokenizers/PHP.php
Expand Up @@ -510,6 +510,7 @@ public function tokenizeString($string, $eolChar='\n')
* braces for scope openers and closers. It also turns some T_FUNCTION tokens
* into T_CLOSURE when they are not standard function definitions. It also
* detects short array syntax and converts those square brackets into new tokens.
* It also corrects some usage of the static keyword.
*
* @param array &$tokens The array of tokens to process.
* @param string $eolChar The EOL character to use for splitting strings.
Expand Down Expand Up @@ -585,6 +586,24 @@ public function processAdditional(&$tokens, $eolChar)
}
}

continue;
} else if ($tokens[$i]['code'] === T_STATIC) {
for ($x = ($i - 1); $x > 0; $x--) {
if (in_array($tokens[$x]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
break;
}
}

if ($tokens[$x]['code'] === T_INSTANCEOF) {
$tokens[$i]['code'] = T_STRING;
$tokens[$i]['type'] = 'T_STRING';

if (PHP_CODESNIFFER_VERBOSITY > 1) {
$line = $tokens[$i]['line'];
echo "\t* token $i on line $line changed from T_STATIC to T_STRING".PHP_EOL;
}
}

continue;
}//end if

Expand Down
1 change: 1 addition & 0 deletions package.xml
Expand Up @@ -37,6 +37,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Squiz SelfMemberReferenceSniff can no longer get into an infinite loop when checking a static call with a namespace
-- Thanks to Andy Grunwald for the patch
- Fixed bug #19699 : Generic.Files.LineLength giving false positives when tab-width is used
- Fixed bug #19726 : Wrong number of spaces expected after instanceof static
</notes>
<contents>
<dir name="/">
Expand Down

0 comments on commit 2fc7017

Please sign in to comment.