Skip to content

Commit 6193c67

Browse files
committed
PhpReflection: fixed expanding to FQCN in bracketed namespace
1 parent 770f474 commit 6193c67

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/DI/PhpReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public static function parseUseStatemenets($code, $forClass = NULL)
188188
while (list(, $token) = each($tokens)) {
189189
switch (is_array($token) ? $token[0] : $token) {
190190
case T_NAMESPACE:
191-
$namespace = self::fetch($tokens, [T_STRING, T_NS_SEPARATOR]) . '\\';
191+
$namespace = ltrim(self::fetch($tokens, [T_STRING, T_NS_SEPARATOR]) . '\\', '\\');
192192
$uses = [];
193193
break;
194194

tests/DI/PhpReflection.expandClassName.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ require __DIR__ . '/../bootstrap.php';
1111

1212

1313
require __DIR__ . '/files/expandClass.noNamespace.php';
14+
require __DIR__ . '/files/expandClass.inBracketedNamespace.php';
1415
require __DIR__ . '/files/expandClass.inNamespace.php';
1516

1617
$rcTest = new \ReflectionClass(Test::class);
18+
$rcBTest = new \ReflectionClass(BTest::class);
1719
$rcFoo = new \ReflectionClass(Test\Space\Foo::class);
1820
$rcBar = new \ReflectionClass(Test\Space\Bar::class);
1921

@@ -26,6 +28,8 @@ Assert::exception(function () use ($rcTest) {
2628
Assert::same('A', PhpReflection::expandClassName('A', $rcTest));
2729
Assert::same('A\B', PhpReflection::expandClassName('C', $rcTest));
2830

31+
Assert::same('BTest', PhpReflection::expandClassName('BTest', $rcBTest));
32+
2933
Assert::same('Test\Space\Foo', PhpReflection::expandClassName('self', $rcFoo));
3034
Assert::same('Test\Space\Foo', PhpReflection::expandClassName('Self', $rcFoo));
3135
Assert::same('Test\Space\Foo', PhpReflection::expandClassName('static', $rcFoo));
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace {
4+
class BTest {}
5+
}

0 commit comments

Comments
 (0)