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 phpDocumentor\Reflection\DocBlock\Tags\Param; |
27
|
|
|
use phpDocumentor\Reflection\Php\Argument; |
28
|
|
|
use phpDocumentor\Reflection\Php\Class_; |
29
|
|
|
use phpDocumentor\Reflection\Php\Trait_; |
30
|
|
|
|
31
|
|
|
class TraitBuilder extends Builder { |
32
|
|
|
|
33
|
|
|
protected function render() { |
34
|
|
|
/** @var Trait_ $trait */ |
35
|
|
|
$trait = $this->element; |
36
|
|
|
|
37
|
|
|
$docBlock = $trait->getDocBlock(); |
38
|
|
|
|
39
|
|
|
$this->addH1(self::escape($trait->getFqsen())); |
40
|
|
|
|
41
|
|
|
$namespace = str_replace('\\' . $trait->getName(), '', $trait->getFqsen()); |
42
|
|
|
if($namespace !== '') { |
43
|
|
|
$this->beginPhpDomain('namespace', substr($namespace, 1), false); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$this->beginPhpDomain('trait', $trait->getName(), false); |
47
|
|
|
|
48
|
|
|
$this->indent(); |
49
|
|
|
if ($docBlock) { |
50
|
|
|
$this |
51
|
|
|
->addLine($docBlock->getDescription()) |
52
|
|
|
->addLine(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$usedTraits = ''; |
56
|
|
|
foreach ($trait->getUsedTraits() as $trait) { |
57
|
|
|
$usedTraits .= $this->getLink('trait', $trait) . ' '; |
58
|
|
|
} |
59
|
|
|
$this->addFieldList('Traits', $usedTraits); |
60
|
|
|
|
61
|
|
|
$this->unindent(); |
62
|
|
|
$this->addLine(); |
63
|
|
|
$this->addLine(); |
64
|
|
|
|
65
|
|
|
$this->addH2('Properties'); |
66
|
|
|
foreach ($trait->getProperties() as $property) { |
|
|
|
|
67
|
|
|
$this->addProperty($property); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->addH2('Methods'); |
71
|
|
|
/* Render methods of a trait */ |
72
|
|
View Code Duplication |
foreach ($trait->getMethods() as $method) { |
|
|
|
|
73
|
|
|
$docBlock = $method->getDocBlock(); |
74
|
|
|
$params = []; |
75
|
|
|
if($docBlock !== null) { |
76
|
|
|
/** @var Param $param */ |
77
|
|
|
foreach ($docBlock->getTagsByName('param') as $param) { |
78
|
|
|
$params[$param->getVariableName()] = $param; |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
$args = ''; |
82
|
|
|
/** @var Argument $argument */ |
83
|
|
|
foreach ($method->getArguments() as $argument) { |
84
|
|
|
// TODO: defaults, types |
85
|
|
|
$args .= ' $' . $argument->getName() . ', '; |
86
|
|
|
} |
87
|
|
|
$args = substr($args, 0, -2); |
88
|
|
|
|
89
|
|
|
$modifiers = $method->getVisibility(); |
90
|
|
|
$modifiers .= $method->isAbstract() ? ' abstract' : ''; |
91
|
|
|
$modifiers .= $method->isFinal() ? ' final' : ''; |
92
|
|
|
$modifiers .= $method->isStatic() ? ' static' : ''; |
93
|
|
|
$this->addLine('.. rst-class:: ' . $modifiers)->addLine(); |
94
|
|
|
$this->indent(); |
95
|
|
|
$this->beginPhpDomain('method', $method->getName().'('.$args.')'); |
96
|
|
|
if ($docBlock) |
97
|
|
|
$this->addMultiline($docBlock->getDescription()); |
98
|
|
|
$this->addLine(); |
99
|
|
|
if (!empty($params)) { |
100
|
|
|
foreach ($method->getArguments() as $argument) { |
101
|
|
|
/** @var Param $param */ |
102
|
|
|
$param = $params[$argument->getName()]; |
103
|
|
|
if ($param !== null) |
104
|
|
|
$this->addMultiline(':param ' . $param->getType() . ' $' . $argument->getName() . ': ' . $param->getDescription(), true); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
$this->endPhpDomain('method'); |
108
|
|
|
$this->unindent(); |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
$this->endPhpDomain(); //trait |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.