|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the BEAR.Resource package. |
|
4
|
|
|
* |
|
5
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace BEAR\Resource; |
|
8
|
|
|
|
|
9
|
|
|
use phpDocumentor\Reflection\DocBlockFactory; |
|
10
|
|
|
|
|
11
|
|
|
final class OptionsMethodDocBolck |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Return docBloc and parameter metas of method |
|
15
|
|
|
*/ |
|
16
|
7 |
|
public function __invoke(\ReflectionMethod $method) : array |
|
17
|
|
|
{ |
|
18
|
7 |
|
$docComment = $method->getDocComment(); |
|
19
|
7 |
|
$doc = $paramDoc = []; |
|
20
|
7 |
|
if ($docComment) { |
|
21
|
7 |
|
list($doc, $paramDoc) = $this->docBlock($docComment); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
7 |
|
return [$doc, $paramDoc]; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @return array [$docs, $params] |
|
29
|
|
|
*/ |
|
30
|
7 |
|
private function docBlock(string $docComment) : array |
|
31
|
|
|
{ |
|
32
|
7 |
|
$factory = DocBlockFactory::createInstance(); |
|
33
|
7 |
|
$docblock = $factory->create($docComment); |
|
34
|
7 |
|
$summary = $docblock->getSummary(); |
|
35
|
7 |
|
$docs = $params = []; |
|
36
|
7 |
|
if ($summary) { |
|
37
|
2 |
|
$docs['summary'] = $summary; |
|
38
|
|
|
} |
|
39
|
7 |
|
$description = (string) $docblock->getDescription(); |
|
40
|
7 |
|
if ($description) { |
|
41
|
2 |
|
$docs['description'] = $description; |
|
42
|
|
|
} |
|
43
|
7 |
|
$tags = $docblock->getTagsByName('param'); |
|
44
|
7 |
|
$params = $this->docBlogTags($tags, $params); |
|
45
|
|
|
|
|
46
|
7 |
|
return [$docs, $params]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
7 |
|
private function docBlogTags(array $tags, array $params) : array |
|
50
|
|
|
{ |
|
51
|
7 |
|
foreach ($tags as $tag) { |
|
52
|
|
|
/* @var $tag \phpDocumentor\Reflection\DocBlock\Tags\Param */ |
|
53
|
3 |
|
$varName = $tag->getVariableName(); |
|
54
|
3 |
|
$tagType = (string) $tag->getType(); |
|
55
|
3 |
|
$type = $tagType === 'int' ? 'integer' : $tagType; |
|
56
|
3 |
|
$params[$varName] = [ |
|
57
|
3 |
|
'type' => $type |
|
58
|
|
|
]; |
|
59
|
3 |
|
$description = (string) $tag->getDescription(); |
|
60
|
3 |
|
if ($description) { |
|
61
|
3 |
|
$params[$varName]['description'] = $description; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
7 |
|
return $params; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|