From f8fe13f3eb33b4c101cd4ba550ae795e2e99c1fa Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 6 Apr 2024 18:49:45 +0200 Subject: [PATCH] More fixes --- src/PhpDoc/ClassDoc.php | 31 ++++++++++++++++--------------- src/PhpDoc/MethodDoc.php | 9 ++------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/PhpDoc/ClassDoc.php b/src/PhpDoc/ClassDoc.php index e8b250a..a08b22e 100644 --- a/src/PhpDoc/ClassDoc.php +++ b/src/PhpDoc/ClassDoc.php @@ -3,6 +3,7 @@ namespace danog\PhpDoc\PhpDoc; use danog\PhpDoc\PhpDoc; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; @@ -49,20 +50,20 @@ class ClassDoc extends GenericDoc $type = (string) $type; $name = $property->getName(); $comment = ''; - foreach ($this->builder->parse($property->getDocComment() ?: '/** */')->getTags() as $tag) { - if ($tag->name === '@var') { - $tag = $tag->value; - \assert($tag instanceof VarTagValueNode); - $type = (string) $tag->type; - $comment = $tag->description; - break; + foreach ($this->builder->parse($property->getDocComment() ?: '/** */')->children as $tag) { + if ($tag instanceof PhpDocTagNode) { + if ($tag->name === '@var') { + $tag = $tag->value; + \assert($tag instanceof VarTagValueNode); + $type = (string) $tag->type; + $comment .= $tag->description."\n"; + break; + } elseif ($tag->name === '@internal') { + continue 2; + } + } elseif ($tag instanceof PhpDocTextNode) { + $comment .= $tag->text."\n"; } - if ($tag->name === 'internal') { - continue 2; - } - } - if (!$comment) { - $comment = \trim($property->getDocComment() ?: '', "\n/* "); } $docReflection .= " * @property $type \$$name $comment\n"; } @@ -71,7 +72,7 @@ class ClassDoc extends GenericDoc $tags = \array_merge($docReflection->getTags(), $doc->getTags()); foreach ($tags as $tag) { - if ($tag->name === 'property') { + if ($tag->name === '@property') { $tag = $tag->value; \assert($tag instanceof PropertyTagValueNode); /** @psalm-suppress InvalidPropertyAssignmentValue */ @@ -140,7 +141,7 @@ class ClassDoc extends GenericDoc if ($this->properties) { $init .= "## Properties\n"; foreach ($this->properties as $name => [$type, $description]) { - $init .= "* `\$$name`: `$type` $description"; + $init .= "* `$name`: `$type` $description"; $init .= "\n"; } } diff --git a/src/PhpDoc/MethodDoc.php b/src/PhpDoc/MethodDoc.php index 0593bc4..f8f8d8c 100644 --- a/src/PhpDoc/MethodDoc.php +++ b/src/PhpDoc/MethodDoc.php @@ -138,12 +138,7 @@ class MethodDoc extends GenericDoc */ public function getSignatureAnchor(): string { - $sig = $this->getSignature(); - $sigLink = \strtolower($sig); - $sigLink = \preg_replace('/[^\w ]+/', ' ', $sigLink); - $sigLink = \preg_replace('/ +/', ' ', $sigLink); - $sigLink = \str_replace(' ', '-', $sigLink); - return \trim($sigLink, '-'); + return $this->name; } /** * Generate markdown for method. @@ -152,7 +147,7 @@ class MethodDoc extends GenericDoc */ public function format(?string $namespace = null): string { - $sig = '### `'.$this->getSignature()."`"; + $sig = '### `'.$this->getSignature()."`"; $sig .= "\n\n"; $sig .= $this->title; $sig .= "\n";