More tidying.
[yaffs-website] / vendor / consolidation / annotated-command / src / Parser / Internal / CommandDocBlockParser2.php
1 <?php
2 namespace Consolidation\AnnotatedCommand\Parser\Internal;
3
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;
9
10 /**
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.
14  */
15 class CommandDocBlockParser2 extends AbstractCommandDocBlockParser
16 {
17     /**
18      * Parse the docBlock comment for this command, and set the
19      * fields of this class with the data thereby obtained.
20      */
21     public function parse()
22     {
23         $docblockComment = $this->reflection->getDocComment();
24         $phpdoc = new DocBlock($docblockComment);
25
26         // First set the description (synopsis) and help.
27         $this->commandInfo->setDescription((string)$phpdoc->getShortDescription());
28         $this->commandInfo->setHelp((string)$phpdoc->getLongDescription());
29
30         $this->processAllTags($phpdoc);
31     }
32
33     protected function getTagContents($tag)
34     {
35         return $tag->getContent();
36     }
37
38     /**
39      * Store the data from a @arg annotation in our argument descriptions.
40      */
41     protected function processArgumentTag($tag)
42     {
43         if (!$this->pregMatchNameAndDescription((string)$tag->getDescription(), $match)) {
44             return;
45         }
46         $this->addOptionOrArgumentTag($tag, $this->commandInfo->arguments(), $match);
47     }
48
49     /**
50      * Store the data from a @param annotation in our argument descriptions.
51      */
52     protected function processParamTag($tag)
53     {
54         if (!$tag instanceof ParamTag) {
55             return;
56         }
57         return parent::processParamTag($tag);
58     }
59
60     /**
61      * Store the data from a @return annotation in our argument descriptions.
62      */
63     protected function processReturnTag($tag)
64     {
65         if (!$tag instanceof ReturnTag) {
66             return;
67         }
68         $this->commandInfo->setReturnType($tag->getType());
69     }
70 }