Permalink
Browse files

Fix scanning of empty namespace{} blocks

  • Loading branch information...
1 parent 16da82d commit 5a763cf010b4796c438ae72514ba73fe32fdc01b @Seldaek Seldaek committed Nov 11, 2012
View
9 src/Composer/Autoload/ClassMapGenerator.php
@@ -92,10 +92,10 @@ public static function createMap($dir, $whitelist = null)
*/
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 @@ private static function findClasses($path)
// strip strings
$contents = preg_replace('{"[^"\\\\]*(\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(\\\\.[^\'\\\\]*)*\'}', 'null', $contents);
- preg_match_all('{(?:\b(?<![\$:>])(?<type>class|interface'.$traits.')\s+(?<name>\S+)|\b(?<![\$:>])(?<ns>namespace)(?<nsname>\s+[^\s;{}\\\\]+(?:\s*\\\\\s*[^\s;{}\\\\]+)*|\s*\{))}i', $contents, $matches);
+ preg_match_all('{
+ (?:
+ \b(?<![\$:>])(?<type>class|interface'.$traits.') \s+ (?<name>\S+)
+ | \b(?<![\$:>])(?<ns>namespace) (?<nsname>\s+[^\s;{}\\\\]+(?:\s*\\\\\s*[^\s;{}\\\\]+)*)? \s*[\{;]
+ )
+ }ix', $contents, $matches);
$classes = array();
$namespace = '';
View
6 tests/Composer/Test/Autoload/ClassMapGeneratorTest.php
@@ -44,11 +44,11 @@ public function getTestCreateMapTests()
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',
View
8 tests/Composer/Test/Autoload/Fixtures/classmap/multipleNs.php
@@ -1,14 +1,14 @@
<?php
-namespace {
+namespace Alpha {
class A {}
+ class B {}
}
-namespace Alpha {
+namespace {
class A {}
- class B {}
}
-namespace Beta {
+namespace Be \ ta {
class A {}
class B {}
}

0 comments on commit 5a763cf

Please sign in to comment.