Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0b1b275

Browse filesBrowse files
committed
[PropertyInfo] Fix PHPStan properties type in trait
1 parent 2c9352d commit 0b1b275
Copy full SHA for 0b1b275

File tree

Expand file treeCollapse file tree

5 files changed

+31
-0
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+31
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php
+8Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php
+2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/Fixtures/TraitUsage/DummyUsingTrait.php
+3Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.