diff --git a/src/Visitor/AttributeRewriteVisitor.php b/src/Visitor/AttributeRewriteVisitor.php index e9aa2f1..3a7f761 100644 --- a/src/Visitor/AttributeRewriteVisitor.php +++ b/src/Visitor/AttributeRewriteVisitor.php @@ -352,12 +352,12 @@ protected function refactorCommentsProperty(array $comments, array $props): ?str { $methodComments[] = '* ' . $meta['comment']; } - if (empty($prop->type)) + if (empty($prop->type) && isset($meta['type'])) { // 使用文档注解类型 $methodComments[] = "* @var {$meta['type']}"; } - elseif (str_contains($propRawType = $this->generator->getPrinter()->prettyPrint([$prop->type]), 'callable') || str_contains($meta['type'], 'callable')) + elseif (($prop->type && str_contains($propRawType = $this->generator->getPrinter()->prettyPrint([$prop->type]), 'callable')) || str_contains($meta['type'] ?? '', 'callable')) { // callable 不能作为属性类型 $propRawType = $propRawType ?: $meta['type'];