mirror of
https://github.com/danog/phpdoc.git
synced 2024-11-30 04:29:12 +01:00
More fixes
This commit is contained in:
parent
e3c13d54aa
commit
f8fe13f3eb
@ -3,6 +3,7 @@
|
|||||||
namespace danog\PhpDoc\PhpDoc;
|
namespace danog\PhpDoc\PhpDoc;
|
||||||
|
|
||||||
use danog\PhpDoc\PhpDoc;
|
use danog\PhpDoc\PhpDoc;
|
||||||
|
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
|
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
|
||||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
|
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
|
||||||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
||||||
@ -49,20 +50,20 @@ class ClassDoc extends GenericDoc
|
|||||||
$type = (string) $type;
|
$type = (string) $type;
|
||||||
$name = $property->getName();
|
$name = $property->getName();
|
||||||
$comment = '';
|
$comment = '';
|
||||||
foreach ($this->builder->parse($property->getDocComment() ?: '/** */')->getTags() as $tag) {
|
foreach ($this->builder->parse($property->getDocComment() ?: '/** */')->children as $tag) {
|
||||||
|
if ($tag instanceof PhpDocTagNode) {
|
||||||
if ($tag->name === '@var') {
|
if ($tag->name === '@var') {
|
||||||
$tag = $tag->value;
|
$tag = $tag->value;
|
||||||
\assert($tag instanceof VarTagValueNode);
|
\assert($tag instanceof VarTagValueNode);
|
||||||
$type = (string) $tag->type;
|
$type = (string) $tag->type;
|
||||||
$comment = $tag->description;
|
$comment .= $tag->description."\n";
|
||||||
break;
|
break;
|
||||||
}
|
} elseif ($tag->name === '@internal') {
|
||||||
if ($tag->name === 'internal') {
|
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
|
} elseif ($tag instanceof PhpDocTextNode) {
|
||||||
|
$comment .= $tag->text."\n";
|
||||||
}
|
}
|
||||||
if (!$comment) {
|
|
||||||
$comment = \trim($property->getDocComment() ?: '', "\n/* ");
|
|
||||||
}
|
}
|
||||||
$docReflection .= " * @property $type \$$name $comment\n";
|
$docReflection .= " * @property $type \$$name $comment\n";
|
||||||
}
|
}
|
||||||
@ -71,7 +72,7 @@ class ClassDoc extends GenericDoc
|
|||||||
|
|
||||||
$tags = \array_merge($docReflection->getTags(), $doc->getTags());
|
$tags = \array_merge($docReflection->getTags(), $doc->getTags());
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
if ($tag->name === 'property') {
|
if ($tag->name === '@property') {
|
||||||
$tag = $tag->value;
|
$tag = $tag->value;
|
||||||
\assert($tag instanceof PropertyTagValueNode);
|
\assert($tag instanceof PropertyTagValueNode);
|
||||||
/** @psalm-suppress InvalidPropertyAssignmentValue */
|
/** @psalm-suppress InvalidPropertyAssignmentValue */
|
||||||
@ -140,7 +141,7 @@ class ClassDoc extends GenericDoc
|
|||||||
if ($this->properties) {
|
if ($this->properties) {
|
||||||
$init .= "## Properties\n";
|
$init .= "## Properties\n";
|
||||||
foreach ($this->properties as $name => [$type, $description]) {
|
foreach ($this->properties as $name => [$type, $description]) {
|
||||||
$init .= "* `\$$name`: `$type` $description";
|
$init .= "* `$name`: `$type` $description";
|
||||||
$init .= "\n";
|
$init .= "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,12 +138,7 @@ class MethodDoc extends GenericDoc
|
|||||||
*/
|
*/
|
||||||
public function getSignatureAnchor(): string
|
public function getSignatureAnchor(): string
|
||||||
{
|
{
|
||||||
$sig = $this->getSignature();
|
return $this->name;
|
||||||
$sigLink = \strtolower($sig);
|
|
||||||
$sigLink = \preg_replace('/[^\w ]+/', ' ', $sigLink);
|
|
||||||
$sigLink = \preg_replace('/ +/', ' ', $sigLink);
|
|
||||||
$sigLink = \str_replace(' ', '-', $sigLink);
|
|
||||||
return \trim($sigLink, '-');
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Generate markdown for method.
|
* Generate markdown for method.
|
||||||
@ -152,7 +147,7 @@ class MethodDoc extends GenericDoc
|
|||||||
*/
|
*/
|
||||||
public function format(?string $namespace = null): string
|
public function format(?string $namespace = null): string
|
||||||
{
|
{
|
||||||
$sig = '### `'.$this->getSignature()."`";
|
$sig = '### <a name="'.$this->name.'"></a> `'.$this->getSignature()."`";
|
||||||
$sig .= "\n\n";
|
$sig .= "\n\n";
|
||||||
$sig .= $this->title;
|
$sig .= $this->title;
|
||||||
$sig .= "\n";
|
$sig .= "\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user