8000 bug #44430 [PropertyInfo] Fix aliased namespace matching (Korbeil) · symfony/symfony@4d9f1aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d9f1aa

Browse files
bug #44430 [PropertyInfo] Fix aliased namespace matching (Korbeil)
This PR was merged into the 5.4 branch. Discussion ---------- [PropertyInfo] Fix aliased namespace matching | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #44417 | License | MIT | Doc PR | N/A When you have an aliased namespace that you use in your code it was erroring because we didn't stored the first part of the namespace that should be replaced. Commits ------- 432b1a1 Fix aliased namespaces matching
2 parents 446686a + 432b1a1 commit 4d9f1aa

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/Symfony/Component/PropertyInfo/PhpStan/NameScope.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ public function resolveStringName(string $name): string
4141
}
4242

4343
$nameParts = explode('\\', $name);
44-
if (isset($this->uses[$nameParts[0]])) {
44+
$firstNamePart = $nameParts[0];
45+
if (isset($this->uses[$firstNamePart])) {
4546
if (1 === \count($nameParts)) {
46-
return $this->uses[$nameParts[0]];
47+
return $this->uses[$firstNamePart];
4748
}
4849
array_shift($nameParts);
4950

50-
return sprintf('%s\\%s', $this->uses[$nameParts[0]], implode('\\', $nameParts));
51+
return sprintf('%s\\%s', $this->uses[$firstNamePart], implode('\\', $nameParts));
5152
}
5253

5354
if (null !== $this->namespace) {

src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,14 @@ public function unionTypesProvider(): array
370370
['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)]],
371371
];
372372
}
373+
374+
public function testDummyNamespace()
375+
{
376+
$this->assertEquals(
377+
[new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')],
378+
$this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\DummyNamespace', 'dummy')
379+
);
380+
}
373381
}
374382

375383
class PhpStanOmittedParamTagTypeDocBlock
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
13+
14+
use Symfony\Component\PropertyInfo\Tests as TestNamespace;
15+
16+
/**
17+
* @author Baptiste Leduc <baptiste.leduc@gmail.com>
18+
*/
19+
class DummyNamespace
20+
{
21+
/** @var TestNamespace\Fixtures\Dummy */
22+
private $dummy;
23+
}

0 commit comments

Comments
 (0)
0