|
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
|
|
|
if (empty($this->reflection->getDocComment())) { |
|
24
|
|
|
return; |
|
25
|
|
|
} |
|
26
|
|
|
$phpdoc = $this->createDocBlock(); |
|
27
|
|
|
|
|
28
|
|
|
// First set the description (synopsis) and help. |
|
29
|
|
|
$this->commandInfo->setDescription((string)$phpdoc->getSummary()); |
|
30
|
|
|
$this->commandInfo->setHelp((string)$phpdoc->getDescription()); |
|
31
|
|
|
|
|
32
|
|
|
$this->processAllTags($phpdoc); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function createDocBlock() |
|
36
|
|
|
{ |
|
37
|
|
|
$docBlockFactory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
38
|
|
|
$contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory(); |
|
39
|
|
|
|
|
40
|
|
|
return $docBlockFactory->create( |
|
41
|
|
|
$this->reflection, |
|
42
|
|
|
$contextFactory->createFromReflector($this->reflection) |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function getTagContents($tag) |
|
47
|
|
|
{ |
|
48
|
|
|
return (string)$tag; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Store the data from a @param annotation in our argument descriptions. |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function processParamTag($tag) |
|
55
|
|
|
{ |
|
56
|
|
|
if (!$tag instanceof Param) { |
|
57
|
|
|
return; |
|
58
|
|
|
} |
|
59
|
|
|
return parent::processParamTag($tag); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Store the data from a @return annotation in our argument descriptions. |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function processReturnTag($tag) |
|
66
|
|
|
{ |
|
67
|
|
|
if (!$tag instanceof Return_) { |
|
68
|
|
|
return; |
|
69
|
|
|
} |
|
70
|
|
|
// If there is a spurrious trailing space on the return type, remove it. |
|
71
|
|
|
$this->commandInfo->setReturnType(trim($this->getTagContents($tag))); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|