22
22
use PhpParser \Node \Expr \FuncCall ;
23
23
use PhpParser \Node \Scalar \String_ ;
24
24
use PhpParser \Node \Stmt \Class_ ;
25
+ use PhpParser \Node \Stmt \ClassLike ;
25
26
use PhpParser \Node \Stmt \ClassMethod ;
26
27
use PhpParser \Node \Stmt \Expression ;
27
28
use PhpParser \Node \Stmt \Function_ ;
29
+ use PhpParser \Node \Stmt \Namespace_ ;
28
30
use PhpParser \Node \Stmt \Property ;
29
31
use PhpParser \Node \Stmt \Return_ as Stmt_Return ;
30
32
use StubsGenerator \NodeVisitor ;
@@ -35,8 +37,8 @@ class Visitor extends NodeVisitor
35
37
{
36
38
private \phpDocumentor \Reflection \DocBlockFactory $ docBlockFactory ;
37
39
38
- /** @var ? array<string,array<int|string,string>> */
39
- private ? array $ functionMap = null ;
40
+ /** @var array<string,array<int|string,string>> */
41
+ private array $ functionMap ;
40
42
41
43
/** @var array<string, list<\PhpStubs\WordPress\Core\WordPressTag>> */
42
44
private array $ additionalTags = [];
@@ -50,6 +52,7 @@ public function __construct()
50
52
{
51
53
$ this ->docBlockFactory = \phpDocumentor \Reflection \DocBlockFactory::createInstance ();
52
54
$ this ->nodeFinder = new NodeFinder ();
55
+ $ this ->functionMap = require sprintf ('%s/functionMap.php ' , dirname (__DIR__ ));
53
56
}
54
57
55
58
/**
@@ -146,7 +149,7 @@ public function getStubStmts(): array
146
149
147
150
private function postProcessNode (Node $ node ): void
148
151
{
149
- if (property_exists ( $ node, ' stmts ' ) && is_array ( $ node-> stmts ) ) {
152
+ if ($ node instanceof ClassLike || $ node instanceof Namespace_ ) {
150
153
foreach ($ node ->stmts as $ stmt ) {
151
154
$ this ->postProcessNode ($ stmt );
152
155
}
@@ -156,9 +159,10 @@ private function postProcessNode(Node $node): void
156
159
return ;
157
160
}
158
161
159
- $ name = $ node ->getAttribute ('fullSymbolName ' );
162
+ /** @var ?string $fullSymbolName */
163
+ $ fullSymbolName = $ node ->getAttribute ('fullSymbolName ' );
160
164
161
- if ($ name === null ) {
165
+ if ($ fullSymbolName === null ) {
162
166
return ;
163
167
}
164
168
@@ -168,13 +172,13 @@ private function postProcessNode(Node $node): void
168
172
return ;
169
173
}
170
174
171
- $ newDocComment = $ this ->addTags ($ name , $ docComment );
175
+ $ newDocComment = $ this ->addTags ($ fullSymbolName , $ docComment );
172
176
173
177
if ($ newDocComment instanceof Doc) {
174
178
$ node ->setDocComment ($ newDocComment );
175
179
}
176
180
177
- if (! isset ($ this ->additionalTagStrings [$ name ])) {
181
+ if (! isset ($ this ->additionalTagStrings [$ fullSymbolName ])) {
178
182
return ;
179
183
}
180
184
@@ -184,7 +188,7 @@ private function postProcessNode(Node $node): void
184
188
return ;
185
189
}
186
190
187
- $ newDocComment = $ this ->addStringTags ($ name , $ docComment );
191
+ $ newDocComment = $ this ->addStringTags ($ fullSymbolName , $ docComment );
188
192
189
193
if (! ($ newDocComment instanceof Doc)) {
190
194
return ;
@@ -426,16 +430,14 @@ static function (WordPressTag $tag) use ($matchNames): bool {
426
430
*/
427
431
private function getAdditionalTagsFromMap (string $ symbolName ): array
428
432
{
429
- if ($ this ->functionMap === null ) {
430
- $ this ->functionMap = require sprintf ('%s/functionMap.php ' , dirname (__DIR__ ));
431
- }
432
-
433
- if (! isset ($ this ->functionMap [$ symbolName ])) {
433
+ if (! array_key_exists ($ symbolName , $ this ->functionMap )) {
434
434
return [];
435
435
}
436
436
437
437
$ parameters = $ this ->functionMap [$ symbolName ];
438
438
$ returnType = array_shift ($ parameters );
439
+ /** @var array<string, string> $parameters */
440
+
439
441
$ additions = [];
440
442
441
443
foreach ($ parameters as $ paramName => $ paramType ) {
0 commit comments