diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 85e14768d..61cfae4a5 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -92,10 +92,10 @@ class ClassMapGenerator */ private static function findClasses($path) { - $contents = php_strip_whitespace($path); $traits = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait'; try { + $contents = php_strip_whitespace($path); if (!preg_match('{\b(?:class|interface'.$traits.')\b}i', $contents)) { return array(); } @@ -105,7 +105,12 @@ class ClassMapGenerator // strip strings $contents = preg_replace('{"[^"\\\\]*(\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(\\\\.[^\'\\\\]*)*\'}', 'null', $contents); - preg_match_all('{(?:\b(?])(?class|interface'.$traits.')\s+(?\S+)|\b(?])(?namespace)(?\s+[^\s;{}\\\\]+(?:\s*\\\\\s*[^\s;{}\\\\]+)*|\s*\{))}i', $contents, $matches); + preg_match_all('{ + (?: + \b(?])(?class|interface'.$traits.') \s+ (?\S+) + | \b(?])(?namespace) (?\s+[^\s;{}\\\\]+(?:\s*\\\\\s*[^\s;{}\\\\]+)*)? \s*[\{;] + ) + }ix', $contents, $matches); $classes = array(); $namespace = ''; diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index 3937e8a99..f1394fd44 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -44,11 +44,11 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase array(__DIR__.'/Fixtures/classmap', array( 'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php', 'Foo\\Bar\\B' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php', - 'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php', 'Alpha\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php', 'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php', - 'Beta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php', - 'Beta\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php', + 'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php', + 'Be\\ta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php', + 'Be\\ta\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php', 'ClassMap\\SomeInterface' => realpath(__DIR__).'/Fixtures/classmap/SomeInterface.php', 'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php', 'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php', diff --git a/tests/Composer/Test/Autoload/Fixtures/classmap/multipleNs.php b/tests/Composer/Test/Autoload/Fixtures/classmap/multipleNs.php index d19e07fc1..ab751a969 100644 --- a/tests/Composer/Test/Autoload/Fixtures/classmap/multipleNs.php +++ b/tests/Composer/Test/Autoload/Fixtures/classmap/multipleNs.php @@ -1,14 +1,14 @@