Skip ::class constant

This commit is contained in:
WouterJ 2015-07-27 18:51:30 +02:00
parent 633d0d835c
commit a336f0e98e
3 changed files with 37 additions and 1 deletions

View File

@ -118,6 +118,25 @@ class ClassMapGenerator
case T_CLASS:
case T_INTERFACE:
case SYMFONY_TRAIT:
// Skip usage of ::class constant
$isClassConstant = false;
for ($j = $i - 1; $j > 0; --$j) {
if (is_string($tokens[$j])) {
break;
}
if (T_DOUBLE_COLON === $tokens[$j][0]) {
$isClassConstant = true;
break;
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
break;
}
}
if ($isClassConstant) {
continue;
}
// Find the classname
while (($t = $tokens[++$i]) && is_array($t)) {
if (T_STRING === $t[0]) {

View File

@ -47,7 +47,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider getTestCreateMapTests
*/
public function testDump($directory, $expected)
public function testDump($directory)
{
$this->prepare_workspace();
@ -115,6 +115,12 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
));
}
if (PHP_VERSION_ID >= 50500) {
$data[] = array(__DIR__.'/Fixtures/php5.5', array(
'ClassCons\\Foo' => __DIR__.'/Fixtures/php5.5/class_cons.php',
));
}
return $data;
}

View File

@ -0,0 +1,11 @@
<?php
namespace ClassCons;
class Foo
{
public function __construct()
{
\Foo\TBar/* foo */::class;
}
}