Skip to content

Commit c628b73

Browse files
committed
[PropertyInfo] Fix PHPStan properties type in trait
1 parent 2c9352d commit c628b73

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy