/** * Generate a DocBlock comment. * * @param DocBlock The DocBlock to serialize. * * @return string The serialized doc block. */ public function getDocComment(DocBlock $docblock) { $indent = str_repeat($this->indentString, $this->indent); $firstIndent = $this->isFirstLineIndented ? $indent : ''; $text = $docblock->getText(); if ($this->lineLength) { //3 === strlen(' * ') $wrapLength = $this->lineLength - strlen($indent) - 3; $text = wordwrap($text, $wrapLength); } $text = str_replace("\n", "\n{$indent} * ", $text); $comment = "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n"; /** @var Tag $tag */ foreach ($docblock->getTags() as $tag) { $tagText = (string) $tag; if ($this->lineLength) { $tagText = wordwrap($tagText, $wrapLength); } $tagText = str_replace("\n", "\n{$indent} * ", $tagText); $comment .= "{$indent} * {$tagText}\n"; } $comment .= $indent . ' */'; return $comment; }
/** * @param string $route * * @return string */ protected function getRouteGroup($route) { list($class, $method) = explode('@', $route); $reflection = new ReflectionClass($class); $comment = $reflection->getDocComment(); if ($comment) { $phpdoc = new DocBlock($comment); foreach ($phpdoc->getTags() as $tag) { if ($tag->getName() === 'resource') { return $tag->getContent(); } } } return 'general'; }
/** * @param $route * * @return bool */ private function isRouteVisibleForDocumentation($route) { list($class, $method) = explode('@', $route); $reflection = new ReflectionClass($class); $comment = $reflection->getMethod($method)->getDocComment(); if ($comment) { $phpdoc = new DocBlock($comment); return collect($phpdoc->getTags())->filter(function ($tag) use($route) { return $tag->getName() === 'hideFromAPIDocumentation'; })->isEmpty(); } return true; }
/** * @depends testConstructWithTagsOnly * @covers \phpDocumentor\Reflection\DocBlock::parseTags * * @return void */ public function testParseMultilineTagWithLineBreaks() { $fixture = <<<DOCBLOCK /** * @return void Content on * multiple lines. * * One more, after the break. */ DOCBLOCK; $object = new DocBlock($fixture); $this->assertCount(1, $tags = $object->getTags()); /** @var ReturnTag $tag */ $tag = reset($tags); $this->assertEquals("Content on\n multiple lines.\n\n One more, after the break.", $tag->getDescription()); }