Skip to content

Commit 2005049

Browse files
committed
bug #59681 [TypeInfo] Fix promoted property phpdoc reading (mtarld)
This PR was merged into the 7.2 branch. Discussion ---------- [TypeInfo] Fix promoted property phpdoc reading | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #59650 | License | MIT The read of promoted property's PHPDoc was missing in `PhpDocAwareReflectionTypeResolver`. This PR adds it. Commits ------- 90dc4ee [TypeInfo] Fix promoted property phpdoc reading
2 parents 5d70ef7 + 90dc4ee commit 2005049

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithPhpDoc.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ final class DummyWithPhpDoc
99
*/
1010
public mixed $arrayOfDummies = [];
1111

12+
/**
13+
* @param bool $promoted
14+
*/
15+
public function __construct(
16+
public mixed $promoted,
17+
) {
18+
}
19+
1220
/**
1321
* @param Dummy $dummy
1422
*

src/Symfony/Component/TypeInfo/Tests/TypeResolver/PhpDocAwareReflectionTypeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function testReadPhpDoc()
2828
$reflection = new \ReflectionClass(DummyWithPhpDoc::class);
2929

3030
$this->assertEquals(Type::array(Type::object(Dummy::class)), $resolver->resolve($reflection->getProperty('arrayOfDummies')));
31+
$this->assertEquals(Type::bool(), $resolver->resolve($reflection->getProperty('promoted')));
3132
$this->assertEquals(Type::object(Dummy::class), $resolver->resolve($reflection->getMethod('getNextDummy')));
3233
$this->assertEquals(Type::object(Dummy::class), $resolver->resolve($reflection->getMethod('getNextDummy')->getParameters()[0]));
3334
}

src/Symfony/Component/TypeInfo/TypeResolver/PhpDocAwareReflectionTypeResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function resolve(mixed $subject, ?TypeContext $typeContext = null): Type
6565
}
6666

6767
$docComment = match (true) {
68-
$subject instanceof \ReflectionProperty => $subject->getDocComment(),
68+
$subject instanceof \ReflectionProperty => $subject->isPromoted() ? $subject->getDeclaringClass()?->getConstructor()?->getDocComment() : $subject->getDocComment(),
6969
$subject instanceof \ReflectionParameter => $subject->getDeclaringFunction()->getDocComment(),
7070
$subject instanceof \ReflectionFunctionAbstract => $subject->getDocComment(),
7171
};
@@ -77,7 +77,7 @@ public function resolve(mixed $subject, ?TypeContext $typeContext = null): Type
7777
$typeContext ??= $this->typeContextFactory->createFromReflection($subject);
7878

7979
$tagName = match (true) {
80-
$subject instanceof \ReflectionProperty => '@var',
80+
$subject instanceof \ReflectionProperty => $subject->isPromoted() ? '@param' : '@var',
8181
$subject instanceof \ReflectionParameter => '@param',
8282
$subject instanceof \ReflectionFunctionAbstract => '@return',
8383
};

0 commit comments

Comments
 (0)