From 2fc7017e28fd5285deca84b818f6ba1ff732a785 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Mon, 3 Dec 2012 11:21:53 +1100 Subject: [PATCH] Fixed bug #19726 : Wrong number of spaces expected after instanceof static --- .../ScopeKeywordSpacingUnitTest.inc | 6 +++++- CodeSniffer/Tokenizers/PHP.php | 19 +++++++++++++++++++ package.xml | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CodeSniffer/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc b/CodeSniffer/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc index 6b608e93df..0302f39b6f 100644 --- a/CodeSniffer/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc +++ b/CodeSniffer/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc @@ -31,4 +31,8 @@ abstract class Foo return new static(); } } -?> \ No newline at end of file + +if ($geometry instanceof static) { + echo 'foo'; +} +?> diff --git a/CodeSniffer/Tokenizers/PHP.php b/CodeSniffer/Tokenizers/PHP.php index a695883d90..3ef3869b5b 100644 --- a/CodeSniffer/Tokenizers/PHP.php +++ b/CodeSniffer/Tokenizers/PHP.php @@ -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. @@ -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 diff --git a/package.xml b/package.xml index 508f27cc4c..35451c5899 100644 --- a/package.xml +++ b/package.xml @@ -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