|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2017 Julius Härtl <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Julius Härtl <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace JuliusHaertl\PHPDocToRst\Builder; |
|
25
|
|
|
|
|
26
|
|
|
use JuliusHaertl\PHPDocToRst\Extension\Extension; |
|
27
|
|
|
use phpDocumentor\Reflection\DocBlock; |
|
28
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated; |
|
29
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Return_; |
|
30
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\See; |
|
31
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Since; |
|
32
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Throws; |
|
33
|
|
|
use phpDocumentor\Reflection\Element; |
|
34
|
|
|
use phpDocumentor\Reflection\File; |
|
35
|
|
|
use phpDocumentor\Reflection\Fqsen; |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
abstract class Builder extends RstBuilder { |
|
39
|
|
|
|
|
40
|
|
|
/** @var File */ |
|
41
|
|
|
protected $file; |
|
42
|
|
|
|
|
43
|
|
|
/** @var Element */ |
|
44
|
|
|
protected $element; |
|
45
|
|
|
|
|
46
|
|
|
/** @var Extension[] */ |
|
47
|
|
|
protected $extensions = []; |
|
48
|
|
|
|
|
49
|
|
|
private $phpDomains = []; |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
protected abstract function render(); |
|
52
|
|
|
|
|
53
|
|
|
public function __construct($file, $element, $extensions) { |
|
54
|
|
|
$this->file = $file; |
|
55
|
|
|
$this->extensions = $extensions; |
|
56
|
|
|
$this->element = $element; |
|
57
|
|
|
$this->render(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return Element that is used to build the rst file |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getElement() { |
|
64
|
|
|
return $this->element; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getLink($type, $fqsen) { |
|
68
|
|
|
return ':php:' . $type . ':`' . RstBuilder::escape(substr($fqsen, 1)) . '`'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function beginPhpDomain($type, $name, $indent=true) { |
|
72
|
|
|
// FIXME: Add checks if it is properly ended |
|
73
|
|
|
$this->addLine('.. php:' . $type . ':: '. $name)->addLine(); |
|
74
|
|
|
if ($indent === true) { |
|
75
|
|
|
$this->indent(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function endPhpDomain($type='') { |
|
|
|
|
|
|
80
|
|
|
$this->unindent(); |
|
81
|
|
|
$this->addLine(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param string $tag Name of the tag to parse |
|
86
|
|
|
* @param DocBlock $docBlock |
|
87
|
|
|
*/ |
|
88
|
|
|
protected function addDocblockTag($tag, DocBlock $docBlock) { |
|
89
|
|
|
$indent = 0; |
|
90
|
|
|
$tags = $docBlock->getTagsByName($tag); |
|
91
|
|
|
switch ($tag) { |
|
92
|
|
View Code Duplication |
case 'return': |
|
|
|
|
|
|
93
|
|
|
if (sizeof($tags) === 0) continue; |
|
94
|
|
|
/** @var Return_ $return */ |
|
95
|
|
|
$return = $tags[0]; |
|
96
|
|
|
$this->addIndentMultiline($indent, ':returns: ' . $return->getType() . ' ' . RstBuilder::escape($return->getDescription()), true); |
|
97
|
|
|
break; |
|
98
|
|
View Code Duplication |
case 'throws': |
|
|
|
|
|
|
99
|
|
|
if (sizeof($tags) === 0) continue; |
|
100
|
|
|
/** @var Throws $return */ |
|
101
|
|
|
$return = $tags[0]; |
|
102
|
|
|
$this->addIndentMultiline($indent, ':throws: ' . $return->getType() . ' ' . RstBuilder::escape($return->getDescription()), true); |
|
103
|
|
|
break; |
|
104
|
|
View Code Duplication |
case 'since': |
|
|
|
|
|
|
105
|
|
|
if (sizeof($tags) === 0) continue; |
|
106
|
|
|
/** @var Since $return */ |
|
107
|
|
|
$return = $tags[0]; |
|
108
|
|
|
$this->addIndentMultiline($indent, ':since: ' . $return->getVersion() . ' ' . RstBuilder::escape($return->getDescription()), true); |
|
109
|
|
|
break; |
|
110
|
|
View Code Duplication |
case 'deprecated': |
|
|
|
|
|
|
111
|
|
|
if (sizeof($tags) === 0) continue; |
|
112
|
|
|
/** @var Deprecated $return */ |
|
113
|
|
|
$return = $tags[0]; |
|
114
|
|
|
$this->addIndentMultiline($indent, ':deprecated: ' . $return->getVersion() . ' ' . RstBuilder::escape($return->getDescription()), true); |
|
115
|
|
|
break; |
|
116
|
|
View Code Duplication |
case 'see': |
|
|
|
|
|
|
117
|
|
|
if (sizeof($tags) === 0) continue; |
|
118
|
|
|
/** @var See $return */ |
|
119
|
|
|
$return = $tags[0]; |
|
120
|
|
|
$this->addIndentMultiline($indent, ':see: ' . $return->getReference() . ' ' . RstBuilder::escape($return->getDescription()), true); |
|
121
|
|
|
break; |
|
122
|
|
|
case 'license': |
|
123
|
|
|
if (sizeof($tags) === 0) continue; |
|
124
|
|
|
/** @var DocBlock\Tags\BaseTag $return */ |
|
125
|
|
|
$return = $tags[0]; |
|
126
|
|
|
$this->addIndentMultiline($indent, ':license: ' . RstBuilder::escape($return->getDescription()), true); |
|
127
|
|
|
break; |
|
128
|
|
|
case 'param': |
|
129
|
|
|
// param handling is done by subclasses since it is more that docbook parsing |
|
130
|
|
|
break; |
|
131
|
|
|
default: |
|
132
|
|
|
echo 'Tag handling not defined for: ' . $tag . PHP_EOL; |
|
133
|
|
|
break; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.