Skip to content

Commit 17f36ad

Browse files
committed
Support @var comment in Builder\ClassPropertyBuilder::fromNode() - Close #43
1 parent 0ad3abd commit 17f36ad

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Builder/ClassPropertyBuilder.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OpenCodeModeling\CodeAst\Code\DocBlock\DocBlock;
1515
use OpenCodeModeling\CodeAst\Code\PropertyGenerator;
1616
use OpenCodeModeling\CodeAst\NodeVisitor\Property;
17+
use PhpParser\Comment\Doc;
1718
use PhpParser\Node;
1819
use PhpParser\NodeTraverser;
1920
use PhpParser\NodeVisitor;
@@ -66,6 +67,20 @@ public static function fromNode(Node\Stmt\Property $node, bool $typed = true): s
6667
$self->visibility = $node->flags;
6768
$self->typed = $typed;
6869

70+
$comments = $node->getAttribute('comments');
71+
72+
if ($comments !== null
73+
&& $comments[0] instanceof Doc
74+
) {
75+
$comments = \explode("\n", $comments[0]->getReformattedText());
76+
77+
foreach ($comments as $comment) {
78+
if (0 === \strpos($comment, ' * @var ')) {
79+
$self->setTypeDocBlockHint(\substr($comment, 8));
80+
}
81+
}
82+
}
83+
6984
return $self;
7085
}
7186

0 commit comments

Comments
 (0)