Skip to content

[TypeInfo] Fix promoted property phpdoc reading #59681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[TypeInfo] Fix promoted property phpdoc reading
  • Loading branch information
mtarld committed Feb 3, 2025
commit 90dc4ee8139df1b10b379f87dd72da7af250dfac
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ final class DummyWithPhpDoc
*/
public mixed $arrayOfDummies = [];

/**
* @param bool $promoted
*/
public function __construct(
public mixed $promoted,
) {
}

/**
* @param Dummy $dummy
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function testReadPhpDoc()
$reflection = new \ReflectionClass(DummyWithPhpDoc::class);

$this->assertEquals(Type::array(Type::object(Dummy::class)), $resolver->resolve($reflection->getProperty('arrayOfDummies')));
$this->assertEquals(Type::bool(), $resolver->resolve($reflection->getProperty('promoted')));
$this->assertEquals(Type::object(Dummy::class), $resolver->resolve($reflection->getMethod('getNextDummy')));
$this->assertEquals(Type::object(Dummy::class), $resolver->resolve($reflection->getMethod('getNextDummy')->getParameters()[0]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function resolve(mixed $subject, ?TypeContext $typeContext = null): Type
}

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

$tagName = match (true) {
$subject instanceof \ReflectionProperty => '@var',
$subject instanceof \ReflectionProperty => $subject->isPromoted() ? '@param' : '@var',
$subject instanceof \ReflectionParameter => '@param',
$subject instanceof \ReflectionFunctionAbstract => '@return',
};
Expand Down
Loading