1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: jus |
5
|
|
|
* Date: 07.10.17 |
6
|
|
|
* Time: 23:25 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace JuliusHaertl\PHPDocToRst\Builder; |
10
|
|
|
|
11
|
|
|
use phpDocumentor\Reflection\DocBlock; |
12
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Return_; |
13
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\See; |
14
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Since; |
15
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Throws; |
16
|
|
|
use phpDocumentor\Reflection\Php\Constant; |
17
|
|
|
use phpDocumentor\Reflection\Php\Property; |
18
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated; |
19
|
|
|
|
20
|
|
|
class PhpDomainBuilder extends RstBuilder { |
21
|
|
|
|
22
|
|
|
protected function addConstant(Constant $constant) { |
23
|
|
|
$this->beginPhpDomain('const', $constant->getName() . ' = ' . $constant->getValue()); |
24
|
|
|
$docBlock = $constant->getDocBlock(); |
25
|
|
|
if ($docBlock) { |
26
|
|
|
foreach ($docBlock->getTags() as $tag) { |
27
|
|
|
$this->addDocblockTag( $tag->getName(), $docBlock); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
$this->endPhpDomain(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function addProperty(Property $property) { |
34
|
|
|
$this->beginPhpDomain('attr', $property->getName()); |
35
|
|
|
$this->endPhpDomain(); |
36
|
|
|
} |
37
|
|
|
public function getLink($type, $fqsen) { |
38
|
|
|
return ':php:' . $type . ':`' . RstBuilder::escape(substr($fqsen, 1)) . '`'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function beginPhpDomain($type, $name, $indent=true) { |
42
|
|
|
// FIXME: Add checks if it is properly ended |
43
|
|
|
$this->addLine('.. php:' . $type . ':: '. $name)->addLine(); |
44
|
|
|
if ($indent === true) { |
45
|
|
|
$this->indent(); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function endPhpDomain($type='') { |
|
|
|
|
50
|
|
|
$this->unindent(); |
51
|
|
|
$this->addLine(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $tag Name of the tag to parse |
56
|
|
|
* @param DocBlock $docBlock |
57
|
|
|
*/ |
58
|
|
|
protected function addDocblockTag($tag, DocBlock $docBlock) { |
59
|
|
|
$tags = $docBlock->getTagsByName($tag); |
60
|
|
|
switch ($tag) { |
61
|
|
View Code Duplication |
case 'return': |
|
|
|
|
62
|
|
|
if (count($tags) === 0) continue; |
63
|
|
|
/** @var Return_ $return */ |
64
|
|
|
$return = $tags[0]; |
65
|
|
|
$this->addMultiline(':returns: ' . $return->getType() . ' ' . RstBuilder::escape($return->getDescription()), true); |
66
|
|
|
break; |
67
|
|
View Code Duplication |
case 'throws': |
|
|
|
|
68
|
|
|
if (count($tags) === 0) continue; |
69
|
|
|
/** @var Throws $return */ |
70
|
|
|
$return = $tags[0]; |
71
|
|
|
$this->addMultiline(':throws: ' . $return->getType() . ' ' . RstBuilder::escape($return->getDescription()), true); |
72
|
|
|
break; |
73
|
|
View Code Duplication |
case 'since': |
|
|
|
|
74
|
|
|
if (count($tags) === 0) continue; |
75
|
|
|
/** @var Since $return */ |
76
|
|
|
$return = $tags[0]; |
77
|
|
|
$this->addMultiline(':since: ' . $return->getVersion() . ' ' . RstBuilder::escape($return->getDescription()), true); |
78
|
|
|
break; |
79
|
|
View Code Duplication |
case 'deprecated': |
|
|
|
|
80
|
|
|
if (count($tags) === 0) continue; |
81
|
|
|
/** @var Deprecated $return */ |
82
|
|
|
$return = $tags[0]; |
83
|
|
|
$this->addMultiline(':deprecated: ' . $return->getVersion() . ' ' . RstBuilder::escape($return->getDescription()), true); |
84
|
|
|
break; |
85
|
|
View Code Duplication |
case 'see': |
|
|
|
|
86
|
|
|
if (count($tags) === 0) continue; |
87
|
|
|
/** @var See $return */ |
88
|
|
|
$return = $tags[0]; |
89
|
|
|
$this->addMultiline(':see: ' . $return->getReference() . ' ' . RstBuilder::escape($return->getDescription()), true); |
90
|
|
|
break; |
91
|
|
View Code Duplication |
case 'license': |
|
|
|
|
92
|
|
|
if (count($tags) === 0) continue; |
93
|
|
|
/** @var DocBlock\Tags\BaseTag $return */ |
94
|
|
|
$return = $tags[0]; |
95
|
|
|
$this->addMultiline(':license: ' . RstBuilder::escape($return->getDescription()), true); |
96
|
|
|
break; |
97
|
|
|
case 'param': |
98
|
|
|
// param handling is done by subclasses since it is more that docbook parsing |
99
|
|
|
break; |
100
|
|
|
default: |
101
|
|
|
//echo 'Tag handling not defined for: ' . $tag . PHP_EOL; |
102
|
|
|
break; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.