diff --git a/src/PhpDoc/ClassDoc.php b/src/PhpDoc/ClassDoc.php index bad96fd..b0bdd8c 100644 --- a/src/PhpDoc/ClassDoc.php +++ b/src/PhpDoc/ClassDoc.php @@ -131,7 +131,7 @@ class ClassDoc extends GenericDoc $init .= "\n"; $init .= "## Method list:\n"; foreach ($this->methods as $method) { - $init .= "* `".$method->getSignature()."`\n"; + $init .= "* ".$method->getSignatureLink()."\n"; } $init .= "\n"; $init .= "## Methods:\n"; diff --git a/src/PhpDoc/MethodDoc.php b/src/PhpDoc/MethodDoc.php index 2b22f81..9b649fa 100644 --- a/src/PhpDoc/MethodDoc.php +++ b/src/PhpDoc/MethodDoc.php @@ -45,7 +45,15 @@ class MethodDoc extends GenericDoc parent::__construct($doc, $method instanceof ReflectionMethod ? $method->getDeclaringClass() : $method); - foreach ($doc->getTags() as $tag) { + $docReflection = "/**\n"; + foreach ($method->getParameters() as $param) { + $type = (string) ($param->getType() ?? 'mixed'); + $docReflection .= " * @param $type \$".$param->getName()."\n"; + } + $docReflection .= ' * @return '.($method->getReturnType() ?? 'mixed')."\n*/"; + $docReflection = $this->builder->getFactory()->create($docReflection); + + foreach ([...$doc->getTags(), ...$docReflection->getTags()] as $tag) { if ($tag instanceof Param && !isset($this->params[$tag->getVariableName()])) { $this->params[$tag->getVariableName()] = [ $tag->getType(), @@ -108,6 +116,20 @@ class MethodDoc extends GenericDoc } return $sig; } + /** + * Get method signature link. + * + * @return string + */ + public function getSignatureLink(): string + { + $sig = $this->getSignature(); + $sigLink = strtolower($sig); + $sigLink = preg_replace('/[^\w ]+/', ' ', $sigLink); + $sigLink = preg_replace('/ +/', ' ', $sigLink); + $sigLink = str_replace(' ', '-', $sigLink); + return "[`$sig`](#$sigLink)"; + } /** * Generate markdown for method. * @@ -145,6 +167,7 @@ class MethodDoc extends GenericDoc } $sig .= $this->seeAlso($namespace ?? $this->namespace); $sig .= "\n"; + return $sig; } }