Permalink
Browse files

Fixed bug #20043 : Mis-interpretation of Foo::class

  • Loading branch information...
1 parent 2a8c5d7 commit 4c9d914afa586f9860078606ed5938869263c9a9 @gsherwood gsherwood committed Sep 5, 2013
@@ -62,6 +62,13 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
return;
}
+ // Special case for PHP 5.5 class name resolution.
+ if (strtolower($constName) === 'class'
+ && $tokens[($stackPtr - 1)]['code'] === T_DOUBLE_COLON
+ ) {
+ return;
+ }
+
// Special case for PHPUnit.
if ($constName === 'PHPUnit_MAIN_METHOD') {
return;
@@ -142,4 +142,12 @@ class MyClass {
}
}
+class Foo
+{
+ public function bar()
+ {
+ return Bar::class;
+ }
+}
+
?>
@@ -510,7 +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.
+ * It also corrects some usage of the static and class keywords.
*
* @param array &$tokens The array of tokens to process.
* @param string $eolChar The EOL character to use for splitting strings.
@@ -605,6 +605,16 @@ public function processAdditional(&$tokens, $eolChar)
}
continue;
+ } else if ($tokens[$i]['code'] === T_CLASS
+ && $tokens[($i - 1)]['code'] === T_DOUBLE_COLON
+ ) {
+ $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_CLASS to T_STRING".PHP_EOL;
+ }
}//end if
if (($tokens[$i]['code'] !== T_CASE
View
@@ -46,6 +46,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #20026 : Check for multi-line arrays that should be single-line is slightly wrong
-- Adds new error message for single-line arrays that end with a comma
- Fixed bug #20029 : ForbiddenFunction sniff incorrectly recognizes methods in USE clauses
+ - Fixed bug #20043 : Mis-interpretation of Foo::class
- Fixed bug #20044 : PSR1 camelCase check does not ignore leading underscores
- Fixed bug #20045 : Errors about indentation for closures with multi-line 'use' in functions
</notes>

0 comments on commit 4c9d914

Please sign in to comment.