More tidying.
[yaffs-website] / vendor / consolidation / annotated-command / src / Parser / Internal / CommandDocBlockParser3.php
1 <?php
2 namespace Consolidation\AnnotatedCommand\Parser\Internal;
3
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;
8
9 /**
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.
13  */
14 class CommandDocBlockParser3 extends AbstractCommandDocBlockParser
15 {
16     /**
17      * Parse the docBlock comment for this command, and set the
18      * fields of this class with the data thereby obtained.
19      */
20     public function parse()
21     {
22         // DocBlockFactory::create fails if the comment is empty.
23         $docComment = $this->reflection->getDocComment();
24         if (empty($docComment)) {
25             return;
26         }
27         $phpdoc = $this->createDocBlock();
28
29         // First set the description (synopsis) and help.
30         $this->commandInfo->setDescription((string)$phpdoc->getSummary());
31         $this->commandInfo->setHelp((string)$phpdoc->getDescription());
32
33         $this->processAllTags($phpdoc);
34     }
35
36     public function createDocBlock()
37     {
38         $docBlockFactory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
39         $contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory();
40
41         return $docBlockFactory->create(
42             $this->reflection,
43             $contextFactory->createFromReflector($this->reflection)
44         );
45     }
46
47     protected function getTagContents($tag)
48     {
49         return (string)$tag;
50     }
51
52     /**
53      * Store the data from a @param annotation in our argument descriptions.
54      */
55     protected function processParamTag($tag)
56     {
57         if (!$tag instanceof Param) {
58             return;
59         }
60         return parent::processParamTag($tag);
61     }
62
63     /**
64      * Store the data from a @return annotation in our argument descriptions.
65      */
66     protected function processReturnTag($tag)
67     {
68         if (!$tag instanceof Return_) {
69             return;
70         }
71         // If there is a spurrious trailing space on the return type, remove it.
72         $this->commandInfo->setReturnType(trim($this->getTagContents($tag)));
73     }
74 }