diff --git a/API/danog/PhpDoc/PhpDocBuilder.md b/API/danog/PhpDoc/PhpDocBuilder.md index 8d22982..53e65c0 100644 --- a/API/danog/PhpDoc/PhpDocBuilder.md +++ b/API/danog/PhpDoc/PhpDocBuilder.md @@ -34,6 +34,7 @@ Create docblock builder. Parameters: + * `$namespace`: `string` Namespace (defaults to package namespace) @@ -44,6 +45,7 @@ Set authors. Parameters: + * `$authors`: `\phpDocumentor\Reflection\DocBlock\Tags\Author[]` Authors @@ -59,6 +61,7 @@ Set scan mode. Parameters: + * `$mode`: `int` Scan mode. @@ -69,6 +72,7 @@ Set filter to ignore certain classes. Parameters: + * `$ignore`: `callable` Full type: ``` @@ -83,6 +87,7 @@ Set output directory. Parameters: + * `$output`: `string` Output directory @@ -93,6 +98,7 @@ Set project name. Parameters: + * `$name`: `string` Name @@ -103,6 +109,7 @@ Set project description. Parameters: + * `$description`: `string` Project description @@ -113,6 +120,7 @@ Set project image. Parameters: + * `$image`: `string` Project image @@ -123,6 +131,7 @@ Add Jekyll front matter. Parameters: + * `$key`: `string` Key * `$value`: `string` Value @@ -134,6 +143,7 @@ Add Jekyll index front matter. Parameters: + * `$key`: `string` Key * `$value`: `string` Value diff --git a/API/index.md b/API/index.md index 4addced..e6b7874 100644 --- a/API/index.md +++ b/API/index.md @@ -1,6 +1,7 @@ --- -title: danog/phpdoc -description: Simple markdown PHPDOC documentation generator with psalm type annotation support. +description: "Simple markdown PHPDOC documentation generator with psalm type annotation support." +title: "danog/phpdoc" + --- # `danog/phpdoc` diff --git a/composer.json b/composer.json index 7f3e08f..ab0f4c7 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,8 @@ "cs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff --dry-run", "cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff", "psalm": "psalm", - "docs": "@phpdoc" + "docs": "@phpdoc", + "phpdoc": "bin/phpdoc API" }, "config": { "allow-plugins": { diff --git a/src/PhpDoc/ClassDoc.php b/src/PhpDoc/ClassDoc.php index 4471f23..bad96fd 100644 --- a/src/PhpDoc/ClassDoc.php +++ b/src/PhpDoc/ClassDoc.php @@ -114,7 +114,7 @@ class ClassDoc extends GenericDoc * * @return string */ - public function format(): string + public function format(?string $namespace = null): string { $init = parent::format(); if ($this->constants) { @@ -136,7 +136,7 @@ class ClassDoc extends GenericDoc $init .= "\n"; $init .= "## Methods:\n"; foreach ($this->methods as $method) { - $init .= $method->format(); + $init .= $method->format($namespace ?? $this->namespace); $init .= "\n"; } } diff --git a/src/PhpDoc/FunctionDoc.php b/src/PhpDoc/FunctionDoc.php index 70a6284..4e347b8 100644 --- a/src/PhpDoc/FunctionDoc.php +++ b/src/PhpDoc/FunctionDoc.php @@ -37,9 +37,9 @@ class FunctionDoc extends MethodDoc * * @return string */ - public function format(): string + public function format(?string $namespace = null): string { - $formatted = parent::format(); + $formatted = parent::format($namespace); $formatted .= "---\n"; $formatted .= "Generated by [danog/phpdoc](https://phpdoc.daniil.it)\n"; return $formatted; diff --git a/src/PhpDoc/GenericDoc.php b/src/PhpDoc/GenericDoc.php index 8c8ddff..eb1c0c3 100644 --- a/src/PhpDoc/GenericDoc.php +++ b/src/PhpDoc/GenericDoc.php @@ -107,8 +107,10 @@ abstract class GenericDoc * * @return string */ - public function seeAlso(): string + public function seeAlso(string $namespace): string { + $namespace = \explode('\\', $namespace); + $empty = []; $seeAlso = ''; foreach ($this->seeAlso as $see) { @@ -122,28 +124,16 @@ abstract class GenericDoc $seeAlso .= "* `$ref`\n"; continue; } - $from = \explode('\\', $this->resolvedClassName.".md"); + \array_shift($to); + \array_unshift($to, ...\array_fill(0, \count($namespace), '..')); $relPath = $to; - foreach ($from as $depth => $dir) { - // find first non-matching dir - if ($dir === $to[$depth]) { - // ignore this directory - \array_shift($relPath); - } else { - // get number of remaining dirs to $from - $remaining = \count($from) - $depth; - if ($remaining > 1) { - // add traversals up to first matching dir - $padLength = (\count($relPath) + $remaining - 1) * -1; - $relPath = \array_pad($relPath, $padLength, '..'); - break; - } - $relPath[0] = './'.$relPath[0]; - } - } $path = \implode('/', $relPath); + if ($path === '../../../danog/MadelineProto/EventHandler.md') { + \var_dump($namespace); + } + if (!$desc = $see->getDescription()) { if ($desc = $this->builder->getTitle($ref)) { $desc = "`$ref`: $desc"; @@ -168,13 +158,13 @@ abstract class GenericDoc * * @return string */ - public function format(): string + public function format(?string $namespace = null): string { $authors = ''; foreach ($this->authors as $author) { $authors .= "> Author: $author \n"; } - $seeAlso = $this->seeAlso(); + $seeAlso = $this->seeAlso($namespace ?? $this->namespace); $frontMatter = $this->builder->getFrontMatter( [ 'title' => "{$this->name}: {$this->title}", diff --git a/src/PhpDoc/MethodDoc.php b/src/PhpDoc/MethodDoc.php index 0cf4814..2b22f81 100644 --- a/src/PhpDoc/MethodDoc.php +++ b/src/PhpDoc/MethodDoc.php @@ -113,7 +113,7 @@ class MethodDoc extends GenericDoc * * @return string */ - public function format(): string + public function format(?string $namespace = null): string { $sig = '### `'.$this->getSignature()."`"; $sig .= "\n\n"; @@ -143,7 +143,7 @@ class MethodDoc extends GenericDoc if (isset($this->psalmReturn)) { $sig .= "\nFully typed return value:\n```\n".$this->psalmReturn."\n```"; } - $sig .= $this->seeAlso(); + $sig .= $this->seeAlso($namespace ?? $this->namespace); $sig .= "\n"; return $sig; } diff --git a/src/index.md b/src/index.md index e6b7874..d4d4308 100644 --- a/src/index.md +++ b/src/index.md @@ -16,4 +16,4 @@ Simple markdown PHPDOC documentation generator with psalm type annotation suppor --- -Generated by [danog/phpdoc](https://phpdoc.daniil.it). \ No newline at end of file +Generated by [danog/phpdoc](https://phpdoc.daniil.it).