1
0
mirror of https://github.com/danog/phpdoc.git synced 2024-11-26 12:04:47 +01:00
This commit is contained in:
Daniil Gentili 2023-06-11 20:14:48 +02:00
parent 0e907c3db3
commit 1c410ad894
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 25 additions and 2 deletions

View File

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

View File

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