1
0
mirror of https://github.com/danog/phpdoc.git synced 2024-11-26 12:04:47 +01:00

More fixes

This commit is contained in:
Daniil Gentili 2024-04-06 18:49:45 +02:00
parent e3c13d54aa
commit f8fe13f3eb
2 changed files with 18 additions and 22 deletions

View File

@ -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";
}
}

View File

@ -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 = '### <a name="'.$this->name.'"></a> `'.$this->getSignature()."`";
$sig .= "\n\n";
$sig .= $this->title;
$sig .= "\n";