2 namespace Consolidation\AnnotatedCommand\Parser\Internal;
4 use phpDocumentor\Reflection\DocBlock\Tags\Param;
5 use phpDocumentor\Reflection\DocBlock\Tags\Return_;
6 use Consolidation\AnnotatedCommand\Parser\CommandInfo;
7 use Consolidation\AnnotatedCommand\Parser\DefaultsWithDescriptions;
10 * Given a class and method name, parse the annotations in the
11 * DocBlock comment, and provide accessor methods for all of
12 * the elements that are needed to create an annotated Command.
14 class CommandDocBlockParser3 extends AbstractCommandDocBlockParser
17 * Parse the docBlock comment for this command, and set the
18 * fields of this class with the data thereby obtained.
20 public function parse()
22 // DocBlockFactory::create fails if the comment is empty.
23 $docComment = $this->reflection->getDocComment();
24 if (empty($docComment)) {
27 $phpdoc = $this->createDocBlock();
29 // First set the description (synopsis) and help.
30 $this->commandInfo->setDescription((string)$phpdoc->getSummary());
31 $this->commandInfo->setHelp((string)$phpdoc->getDescription());
33 $this->processAllTags($phpdoc);
36 public function createDocBlock()
38 $docBlockFactory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
39 $contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory();
41 return $docBlockFactory->create(
43 $contextFactory->createFromReflector($this->reflection)
47 protected function getTagContents($tag)
53 * Store the data from a @param annotation in our argument descriptions.
55 protected function processParamTag($tag)
57 if (!$tag instanceof Param) {
60 return parent::processParamTag($tag);
64 * Store the data from a @return annotation in our argument descriptions.
66 protected function processReturnTag($tag)
68 if (!$tag instanceof Return_) {
71 // If there is a spurrious trailing space on the return type, remove it.
72 $this->commandInfo->setReturnType(trim($this->getTagContents($tag)));