diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php index afe29bec26117..625845b093dce 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php @@ -287,11 +287,11 @@ public function getLongDescription(string $class, string $property, array $conte } /** - * A docblock is splitted into a template marker, a short description, an optional long description and a tags section. + * A docblock is split into a template marker, a short description, an optional long description and a tags section. * - * - The template marker is either empty, or #@+ or #@-. + * - The template marker is either empty, #@+ or #@-. * - The short description is started from a non-tag character, and until one or multiple newlines. - * - The long description (optional), is started from a non-tag character, and until a new line is encountered followed by a tag. + * - The long description (optional) is started from a non-tag character, and until a new line is encountered followed by a tag. * - Tags, and the remaining characters * * This method returns the short and the long descriptions. @@ -374,7 +374,7 @@ private function getDescriptionsFromDocNode(PhpDocNode $docNode): array ]; } - private function getDocBlockFromConstructor(string $class, string $property): ?ParamTagValueNode + private function getDocBlockFromConstructor(string &$class, string $property): ?ParamTagValueNode { try { $reflectionClass = new \ReflectionClass($class); @@ -389,6 +389,7 @@ private function getDocBlockFromConstructor(string $class, string $property): ?P if (!$rawDocNode = $reflectionConstructor->getDocComment()) { return null; } + $class = $reflectionConstructor->class; $phpDocNode = $this->getPhpDocNode($rawDocNode); diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php index 9a4924f9338dd..2dea9c4c18146 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php @@ -1143,6 +1143,11 @@ public static function descriptionsProvider(): iterable yield ['bal', 'A short description ignoring template.', "A long description...\n\n...over several lines."]; yield ['foo2', null, null]; } + + public function testGetTypeFromConstructorOfParentClass() + { + $this->assertEquals(Type::nullable(Type::object(RootDummyItem::class)), $this->extractor->getTypeFromConstructor(Dummy::class, 'rootDummyItem')); + } } class PhpStanOmittedParamTagTypeDocBlock diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php index 6963f6d531d59..65ba8d85b6305 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php @@ -70,6 +70,14 @@ class ParentDummy */ public $rootDummyItem; + /** + * @param RootDummyItem|null $rootDummyItem + */ + public function __construct(?RootDummyItem $rootDummyItem = null) + { + $this->rootDummyItem = $rootDummyItem; + } + /** * @return bool|null */