From f0d67923a528169569f98fd225822d53b3415f52 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 24 Apr 2016 14:40:51 +0100 Subject: [PATCH] Fix classmap generator over anonymous classes extending/implementing something, fixes #5239 --- src/Composer/Autoload/ClassMapGenerator.php | 4 ++ .../Test/Autoload/ClassMapGeneratorTest.php | 5 +++ .../Autoload/Fixtures/php7.0/anonclass.php | 43 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 tests/Composer/Test/Autoload/Fixtures/php7.0/anonclass.php diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 704d6b39f..5eed9523c 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -188,6 +188,10 @@ class ClassMapGenerator $namespace = str_replace(array(' ', "\t", "\r", "\n"), '', $matches['nsname'][$i]) . '\\'; } else { $name = $matches['name'][$i]; + // skip anon classes extending/implementing + if ($name === 'extends' || $name === 'implements') { + continue; + } if ($name[0] === ':') { // This is an XHP class, https://github.com/facebook/xhp $name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1); diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index 13cf7cd83..4af707160 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -87,6 +87,11 @@ class ClassMapGeneratorTest extends TestCase 'Foo\\CBar' => __DIR__.'/Fixtures/php5.4/traits.php', )); } + if (PHP_VERSION_ID >= 70000) { + $data[] = array(__DIR__.'/Fixtures/php7.0', array( + 'Dummy\Test\AnonClassHolder' => __DIR__.'/Fixtures/php7.0/anonclass.php', + )); + } if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) { $data[] = array(__DIR__.'/Fixtures/hhvm3.3', array( 'FooEnum' => __DIR__.'/Fixtures/hhvm3.3/HackEnum.php', diff --git a/tests/Composer/Test/Autoload/Fixtures/php7.0/anonclass.php b/tests/Composer/Test/Autoload/Fixtures/php7.0/anonclass.php new file mode 100644 index 000000000..44176abe1 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/php7.0/anonclass.php @@ -0,0 +1,43 @@ +