8000 bug #54675 [PropertyInfo] Fix PHPStan properties type in trait (mtarld) · symfony/symfony@a4dc5f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit a4dc5f7

Browse files
bug #54675 [PropertyInfo] Fix PHPStan properties type in trait (mtarld)
This PR was merged into the 5.4 branch. Discussion ---------- [PropertyInfo] Fix PHPStan properties type in trait | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54569 | License | MIT Handle traits properly in `PhpStanExtractor`. Commits ------- 0b1b275 [PropertyInfo] Fix PHPStan properties type in trait
2 parents 2c3bbf4 + 0b1b275 commit a4dc5f7

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ private function getDocBlockFromProperty(string $class, string $property): ?arra
233233
return null;
234234
}
235235

236+
$reflector = $reflectionProperty->getDeclaringClass();
237+
238+
foreach ($reflector->getTraits() as $trait) {
239+
if ($trait->hasProperty($property)) {
240+
return $this->getDocBlockFromProperty($trait->getName(), $property);
241+
}
242+
}
243+
236244
if (null === $rawDocNode = $reflectionProperty->getDocComment() ?: null) {
237245
return null;
238246
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
2020
use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
2121
use Symfony\Component\PropertyInfo\Tests\Fixtures\RootDummy\RootDummyItem;
22+
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\AnotherNamespace\DummyInAnotherNamespace;
2223
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait;
2324
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait;
2425
use Symfony\Component\PropertyInfo\Type;
@@ -311,6 +312,7 @@ public static function propertiesDefinedByTraitsProvider(): array
311312
['propertyInTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
312313
['propertyInTraitObjectSameNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyUsedInTrait::class)],
313314
['propertyInTraitObjectDifferentNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)],
315+
['dummyInAnotherNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyInAnotherNamespace::class)],
314316
];
315317
}
316318

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\AnotherNamespace;
4+
5+
class DummyInAnotherNamespace
6+
{
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\AnotherNamespace;
4+
5+
trait DummyTraitInAnotherNamespace
6+
{
7+
/**
8+
* @var DummyInAnotherNamespace
9+
*/
10+
public $dummyInAnotherNamespace;
11+
}

src/Symfony/Component/PropertyInfo/Tests/Fixtures/TraitUsage/DummyUsingTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212
namespace Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage;
1313

14+
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\AnotherNamespace\DummyTraitInAnotherNamespace;
15+
1416
class DummyUsingTrait
1517
{
1618
use DummyTrait;
19+
use DummyTraitInAnotherNamespace;
1720
}

0 commit comments

Comments
 (0)
0