Skip to content

Commit

Permalink
Added support for @var in promoted properties
Browse files Browse the repository at this point in the history
Closes #21
  • Loading branch information
vudaltsov committed Feb 21, 2024
1 parent a1d1efc commit 3e48f9e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/PhpParserReflector/ContextualPhpParserReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit 3e48f9e

Please sign in to comment.