From 3e48f9e7c42eac81cd9492376885a4b221b98635 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Wed, 21 Feb 2024 04:15:54 +0300 Subject: [PATCH] Added support for @var in promoted properties Closes https://github.com/typhoon-php/reflection/issues/21 --- src/PhpParserReflector/ContextualPhpParserReflector.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PhpParserReflector/ContextualPhpParserReflector.php b/src/PhpParserReflector/ContextualPhpParserReflector.php index 9b0bd8b..831507e 100644 --- a/src/PhpParserReflector/ContextualPhpParserReflector.php +++ b/src/PhpParserReflector/ContextualPhpParserReflector.php @@ -324,7 +324,7 @@ class: $class, return $properties; } - $phpDoc = $this->parsePhpDoc($constructorNode); + $constructorPhpDoc = $this->parsePhpDoc($constructorNode); foreach ($constructorNode->params as $node) { $modifiers = PropertyReflections::promotedModifiers($node, $classReadOnly); @@ -335,11 +335,12 @@ class: $class, \assert($node->var instanceof Expr\Variable && \is_string($node->var->name)); $name = $node->var->name; + $phpDoc = $this->parsePhpDoc($node); $properties[] = new PropertyMetadata( name: $name, class: $class, modifiers: $modifiers, - type: $this->reflectType($node->type, $phpDoc->paramTypes()[$name] ?? null), + type: $this->reflectType($node->type, $phpDoc->varType() ?? $constructorPhpDoc->paramTypes()[$name] ?? null), docComment: $this->reflectDocComment($node), hasDefaultValue: $node->default !== null || $node->type === null, promoted: true,