diff --git a/src/Symfony/Component/PropertyInfo/PhpStan/NameScope.php b/src/Symfony/Component/PropertyInfo/PhpStan/NameScope.php index 8bc9f7dfd4ba3..6722c0fb01f60 100644 --- a/src/Symfony/Component/PropertyInfo/PhpStan/NameScope.php +++ b/src/Symfony/Component/PropertyInfo/PhpStan/NameScope.php @@ -41,13 +41,14 @@ public function resolveStringName(string $name): string } $nameParts = explode('\\', $name); - if (isset($this->uses[$nameParts[0]])) { + $firstNamePart = $nameParts[0]; + if (isset($this->uses[$firstNamePart])) { if (1 === \count($nameParts)) { - return $this->uses[$nameParts[0]]; + return $this->uses[$firstNamePart]; } array_shift($nameParts); - return sprintf('%s\\%s', $this->uses[$nameParts[0]], implode('\\', $nameParts)); + return sprintf('%s\\%s', $this->uses[$firstNamePart], implode('\\', $nameParts)); } if (null !== $this->namespace) { diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php index 8b52433a54fe2..f3d7088dd3eca 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php @@ -370,6 +370,14 @@ public function unionTypesProvider(): array ['e', [new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class, true, [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [], [new Type(Type::BUILTIN_TYPE_STRING)])], [new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [new Type(Type::BUILTIN_TYPE_INT)], [new Type(Type::BUILTIN_TYPE_STRING, false, null, true, [], [new Type(Type::BUILTIN_TYPE_OBJECT, false, DefaultValue::class)])])]), new Type(Type::BUILTIN_TYPE_OBJECT, false, ParentDummy::class)]], ]; } + + public function testDummyNamespace() + { + $this->assertEquals( + [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')], + $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\DummyNamespace', 'dummy') + ); + } } class PhpStanOmittedParamTagTypeDocBlock diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DummyNamespace.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DummyNamespace.php new file mode 100644 index 0000000000000..5159173628d6e --- /dev/null +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DummyNamespace.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyInfo\Tests\Fixtures; + +use Symfony\Component\PropertyInfo\Tests as TestNamespace; + +/** + * @author Baptiste Leduc + */ +class DummyNamespace +{ + /** @var TestNamespace\Fixtures\Dummy */ + private $dummy; +}