Fix scanning of empty namespace{} blocks
parent
16da82db13
commit
5a763cf010
|
@ -92,10 +92,10 @@ class ClassMapGenerator
|
||||||
*/
|
*/
|
||||||
private static function findClasses($path)
|
private static function findClasses($path)
|
||||||
{
|
{
|
||||||
$contents = php_strip_whitespace($path);
|
|
||||||
$traits = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait';
|
$traits = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$contents = php_strip_whitespace($path);
|
||||||
if (!preg_match('{\b(?:class|interface'.$traits.')\b}i', $contents)) {
|
if (!preg_match('{\b(?:class|interface'.$traits.')\b}i', $contents)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,12 @@ class ClassMapGenerator
|
||||||
// strip strings
|
// strip strings
|
||||||
$contents = preg_replace('{"[^"\\\\]*(\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(\\\\.[^\'\\\\]*)*\'}', 'null', $contents);
|
$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();
|
$classes = array();
|
||||||
|
|
||||||
$namespace = '';
|
$namespace = '';
|
||||||
|
|
|
@ -44,11 +44,11 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||||
array(__DIR__.'/Fixtures/classmap', array(
|
array(__DIR__.'/Fixtures/classmap', array(
|
||||||
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
|
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
|
||||||
'Foo\\Bar\\B' => 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\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||||
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||||
'Beta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||||
'Beta\\B' => 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\\SomeInterface' => realpath(__DIR__).'/Fixtures/classmap/SomeInterface.php',
|
||||||
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
|
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
|
||||||
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
|
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
namespace {
|
|
||||||
class A {}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Alpha {
|
namespace Alpha {
|
||||||
class A {}
|
class A {}
|
||||||
class B {}
|
class B {}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Beta {
|
namespace {
|
||||||
|
class A {}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Be \ ta {
|
||||||
class A {}
|
class A {}
|
||||||
class B {}
|
class B {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue