1
0
mirror of https://github.com/danog/phpdoc.git synced 2024-11-30 04:29:12 +01:00
This commit is contained in:
Daniil Gentili 2022-01-08 14:07:03 +01:00
parent 57c168c5d0
commit f6361bfc87
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
8 changed files with 33 additions and 31 deletions

View File

@ -34,6 +34,7 @@ Create docblock builder.
Parameters: Parameters:
* `$namespace`: `string` Namespace (defaults to package namespace) * `$namespace`: `string` Namespace (defaults to package namespace)
@ -44,6 +45,7 @@ Set authors.
Parameters: Parameters:
* `$authors`: `\phpDocumentor\Reflection\DocBlock\Tags\Author[]` Authors * `$authors`: `\phpDocumentor\Reflection\DocBlock\Tags\Author[]` Authors
@ -59,6 +61,7 @@ Set scan mode.
Parameters: Parameters:
* `$mode`: `int` Scan mode. * `$mode`: `int` Scan mode.
@ -69,6 +72,7 @@ Set filter to ignore certain classes.
Parameters: Parameters:
* `$ignore`: `callable` * `$ignore`: `callable`
Full type: Full type:
``` ```
@ -83,6 +87,7 @@ Set output directory.
Parameters: Parameters:
* `$output`: `string` Output directory * `$output`: `string` Output directory
@ -93,6 +98,7 @@ Set project name.
Parameters: Parameters:
* `$name`: `string` Name * `$name`: `string` Name
@ -103,6 +109,7 @@ Set project description.
Parameters: Parameters:
* `$description`: `string` Project description * `$description`: `string` Project description
@ -113,6 +120,7 @@ Set project image.
Parameters: Parameters:
* `$image`: `string` Project image * `$image`: `string` Project image
@ -123,6 +131,7 @@ Add Jekyll front matter.
Parameters: Parameters:
* `$key`: `string` Key * `$key`: `string` Key
* `$value`: `string` Value * `$value`: `string` Value
@ -134,6 +143,7 @@ Add Jekyll index front matter.
Parameters: Parameters:
* `$key`: `string` Key * `$key`: `string` Key
* `$value`: `string` Value * `$value`: `string` Value

View File

@ -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` # `danog/phpdoc`

View File

@ -45,7 +45,8 @@
"cs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff --dry-run", "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", "cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff",
"psalm": "psalm", "psalm": "psalm",
"docs": "@phpdoc" "docs": "@phpdoc",
"phpdoc": "bin/phpdoc API"
}, },
"config": { "config": {
"allow-plugins": { "allow-plugins": {

View File

@ -114,7 +114,7 @@ class ClassDoc extends GenericDoc
* *
* @return string * @return string
*/ */
public function format(): string public function format(?string $namespace = null): string
{ {
$init = parent::format(); $init = parent::format();
if ($this->constants) { if ($this->constants) {
@ -136,7 +136,7 @@ class ClassDoc extends GenericDoc
$init .= "\n"; $init .= "\n";
$init .= "## Methods:\n"; $init .= "## Methods:\n";
foreach ($this->methods as $method) { foreach ($this->methods as $method) {
$init .= $method->format(); $init .= $method->format($namespace ?? $this->namespace);
$init .= "\n"; $init .= "\n";
} }
} }

View File

@ -37,9 +37,9 @@ class FunctionDoc extends MethodDoc
* *
* @return string * @return string
*/ */
public function format(): string public function format(?string $namespace = null): string
{ {
$formatted = parent::format(); $formatted = parent::format($namespace);
$formatted .= "---\n"; $formatted .= "---\n";
$formatted .= "Generated by [danog/phpdoc](https://phpdoc.daniil.it)\n"; $formatted .= "Generated by [danog/phpdoc](https://phpdoc.daniil.it)\n";
return $formatted; return $formatted;

View File

@ -107,8 +107,10 @@ abstract class GenericDoc
* *
* @return string * @return string
*/ */
public function seeAlso(): string public function seeAlso(string $namespace): string
{ {
$namespace = \explode('\\', $namespace);
$empty = []; $empty = [];
$seeAlso = ''; $seeAlso = '';
foreach ($this->seeAlso as $see) { foreach ($this->seeAlso as $see) {
@ -122,28 +124,16 @@ abstract class GenericDoc
$seeAlso .= "* `$ref`\n"; $seeAlso .= "* `$ref`\n";
continue; continue;
} }
$from = \explode('\\', $this->resolvedClassName.".md");
\array_shift($to);
\array_unshift($to, ...\array_fill(0, \count($namespace), '..'));
$relPath = $to; $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); $path = \implode('/', $relPath);
if ($path === '../../../danog/MadelineProto/EventHandler.md') {
\var_dump($namespace);
}
if (!$desc = $see->getDescription()) { if (!$desc = $see->getDescription()) {
if ($desc = $this->builder->getTitle($ref)) { if ($desc = $this->builder->getTitle($ref)) {
$desc = "`$ref`: $desc"; $desc = "`$ref`: $desc";
@ -168,13 +158,13 @@ abstract class GenericDoc
* *
* @return string * @return string
*/ */
public function format(): string public function format(?string $namespace = null): string
{ {
$authors = ''; $authors = '';
foreach ($this->authors as $author) { foreach ($this->authors as $author) {
$authors .= "> Author: $author \n"; $authors .= "> Author: $author \n";
} }
$seeAlso = $this->seeAlso(); $seeAlso = $this->seeAlso($namespace ?? $this->namespace);
$frontMatter = $this->builder->getFrontMatter( $frontMatter = $this->builder->getFrontMatter(
[ [
'title' => "{$this->name}: {$this->title}", 'title' => "{$this->name}: {$this->title}",

View File

@ -113,7 +113,7 @@ class MethodDoc extends GenericDoc
* *
* @return string * @return string
*/ */
public function format(): string public function format(?string $namespace = null): string
{ {
$sig = '### `'.$this->getSignature()."`"; $sig = '### `'.$this->getSignature()."`";
$sig .= "\n\n"; $sig .= "\n\n";
@ -143,7 +143,7 @@ class MethodDoc extends GenericDoc
if (isset($this->psalmReturn)) { if (isset($this->psalmReturn)) {
$sig .= "\nFully typed return value:\n```\n".$this->psalmReturn."\n```"; $sig .= "\nFully typed return value:\n```\n".$this->psalmReturn."\n```";
} }
$sig .= $this->seeAlso(); $sig .= $this->seeAlso($namespace ?? $this->namespace);
$sig .= "\n"; $sig .= "\n";
return $sig; return $sig;
} }