diff --git a/CHANGELOG.md b/CHANGELOG.md index f83b51c..22594be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) --- ## [Unreleased] - +### Fixed +- Invalid tags break the parseDocBlock() ## [v1.0.0] - 2021-07-25 ### Added diff --git a/examples/Library/Acme.php b/examples/Library/Acme.php index 812a534..a9c78ea 100644 --- a/examples/Library/Acme.php +++ b/examples/Library/Acme.php @@ -29,6 +29,8 @@ * @author Another Author * @copyright 2021 (c) Acme Corporation * @license [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT) + * + * @return [type] Show invalid tags as is */ class Acme extends ParentClass implements \Countable { diff --git a/src/DocTracer.php b/src/DocTracer.php index 081e91e..15f95c6 100644 --- a/src/DocTracer.php +++ b/src/DocTracer.php @@ -5,6 +5,7 @@ namespace Mdz; use phpDocumentor\Reflection\DocBlockFactory; +use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag; use Michelf\MarkdownExtra; /** @@ -375,26 +376,28 @@ protected function parseDocBlock(\Reflector $ref): array $i = 0; foreach ($docBlock->getTags() as $docTags) { - if ($docTags->getName() === 'param') { - $tags[$docTags->getName()][$i] = [ - 'name' => '@' . $docTags->getName(), - 'type' => (string)$docTags->getType(), - 'variable' => '$' . $docTags->getVariableName(), - 'description' => $docTags->getDescription()->render(), - ]; - } elseif (in_array($docTags->getName(), ['var', 'return', 'throws'])) { - $tags[$docTags->getName()][$i] = [ - 'name' => '@' . $docTags->getName(), - 'type' => (string)$docTags->getType(), - 'description' => $docTags->getDescription()->render(), - ]; - } else { - $tags[$docTags->getName()][$i] = [ - 'name' => '@' . $docTags->getName(), - ]; + if ($docTags && !$docTags instanceof InvalidTag) { + if ($docTags->getName() === 'param') { + $tags[$docTags->getName()][$i] = [ + 'name' => '@' . $docTags->getName(), + 'type' => (string)$docTags->getType(), + 'variable' => '$' . $docTags->getVariableName(), + 'description' => $docTags->getDescription()->render(), + ]; + } elseif (in_array($docTags->getName(), ['var', 'return', 'throws'])) { + $tags[$docTags->getName()][$i] = [ + 'name' => '@' . $docTags->getName(), + 'type' => (string)$docTags->getType(), + 'description' => $docTags->getDescription()->render(), + ]; + } else { + $tags[$docTags->getName()][$i] = [ + 'name' => '@' . $docTags->getName(), + ]; + } } - $tags[$docTags->getName()][$i]['render'] = trim(str_replace('@' . $docTags->getName(), '', $docTags->render())); + $tags[$docTags->getName()][$i]['render'] = trim($docTags->render()); $i++; } @@ -469,23 +472,42 @@ protected function formatDocBlock(array $docBlock): string foreach ($tags as $tag) { if ($name === 'param') { - $docs .= ''; - $docs .= '' . $tag['name'] . ''; - $docs .= '' . $this->wordbreak($tag['type']) . ''; - $docs .= '' . $tag['variable'] . ''; - $docs .= '' . $this->markdown($tag['description']) . ''; - $docs .= ''; + if (isset($tag['name'])) { + $docs .= ''; + $docs .= '' . $tag['name'] . ''; + $docs .= '' . $this->wordbreak($tag['type']) . ''; + $docs .= '' . $tag['variable'] . ''; + $docs .= '' . $this->markdown($tag['description']) . ''; + $docs .= ''; + } else { + $docs .= ''; + $docs .= '' . $this->markdown($tag['render']) . ''; + $docs .= ''; + } } elseif (in_array($name, ['var', 'return', 'throws'])) { - $docs .= ''; - $docs .= '' . $tag['name'] . ''; - $docs .= '' . $this->wordbreak($tag['type']) . ''; - $docs .= '' . $this->markdown($tag['description']) . ''; - $docs .= ''; + if (isset($tag['name'])) { + $docs .= ''; + $docs .= '' . $tag['name'] . ''; + $docs .= '' . $this->wordbreak($tag['type']) . ''; + $docs .= '' . $this->markdown($tag['description']) . ''; + $docs .= ''; + } else { + $docs .= ''; + $docs .= '' . $this->markdown($tag['render']) . ''; + $docs .= ''; + } } else { - $docs .= ''; - $docs .= '' . $tag['name'] . ''; - $docs .= '' . $this->markdown($tag['render']) . ''; - $docs .= ''; + if (isset($tag['name'])) { + $render = str_replace('@' . $tag['name'], '', $tag['render']); + $docs .= ''; + $docs .= '' . $tag['name'] . ''; + $docs .= '' . $this->markdown($render) . ''; + $docs .= ''; + } else { + $docs .= ''; + $docs .= '' . $this->markdown($tag['render']) . ''; + $docs .= ''; + } } } $docs .= '';