2 namespace Consolidation\AnnotatedCommand\Parser\Internal;
4 use phpDocumentor\Reflection\DocBlock;
5 use phpDocumentor\Reflection\DocBlock\Tag\ParamTag;
6 use phpDocumentor\Reflection\DocBlock\Tag\ReturnTag;
7 use Consolidation\AnnotatedCommand\Parser\CommandInfo;
8 use Consolidation\AnnotatedCommand\Parser\DefaultsWithDescriptions;
11 * Given a class and method name, parse the annotations in the
12 * DocBlock comment, and provide accessor methods for all of
13 * the elements that are needed to create an annotated Command.
15 class CommandDocBlockParser2 extends AbstractCommandDocBlockParser
18 * Parse the docBlock comment for this command, and set the
19 * fields of this class with the data thereby obtained.
21 public function parse()
23 $docblockComment = $this->reflection->getDocComment();
24 $phpdoc = new DocBlock($docblockComment);
26 // First set the description (synopsis) and help.
27 $this->commandInfo->setDescription((string)$phpdoc->getShortDescription());
28 $this->commandInfo->setHelp((string)$phpdoc->getLongDescription());
30 $this->processAllTags($phpdoc);
33 protected function getTagContents($tag)
35 return $tag->getContent();
39 * Store the data from a @arg annotation in our argument descriptions.
41 protected function processArgumentTag($tag)
43 if (!$this->pregMatchNameAndDescription((string)$tag->getDescription(), $match)) {
46 $this->addOptionOrArgumentTag($tag, $this->commandInfo->arguments(), $match);
50 * Store the data from a @param annotation in our argument descriptions.
52 protected function processParamTag($tag)
54 if (!$tag instanceof ParamTag) {
57 return parent::processParamTag($tag);
61 * Store the data from a @return annotation in our argument descriptions.
63 protected function processReturnTag($tag)
65 if (!$tag instanceof ReturnTag) {
68 $this->commandInfo->setReturnType($tag->getType());