@@ -36,13 +36,13 @@ class Visitor extends NodeVisitor
36
36
private \phpDocumentor \Reflection \DocBlockFactory $ docBlockFactory ;
37
37
38
38
/** @var ?array<string,array<int|string,string>> */
39
- private $ functionMap = null ;
39
+ private ? array $ functionMap = null ;
40
40
41
41
/** @var array<string, list<\PhpStubs\WordPress\Core\WordPressTag>> */
42
- private $ additionalTags = [];
42
+ private array $ additionalTags = [];
43
43
44
44
/** @var array<string, list<string>> */
45
- private $ additionalTagStrings = [];
45
+ private array $ additionalTagStrings = [];
46
46
47
47
private \PhpParser \NodeFinder $ nodeFinder ;
48
48
@@ -77,7 +77,7 @@ public function enterNode(Node $node)
77
77
$ parent = $ this ->stack [count ($ this ->stack ) - 2 ];
78
78
\assert ($ parent instanceof \PhpParser \Node \Stmt \ClassLike);
79
79
80
- if (isset ( $ parent ->name ) ) {
80
+ if ($ parent ->name !== null ) {
81
81
$ symbolName = sprintf (
82
82
'%1$s::%2$s ' ,
83
83
$ parent ->name ->name ,
@@ -146,7 +146,7 @@ public function getStubStmts(): array
146
146
147
147
private function postProcessNode (Node $ node ): void
148
148
{
149
- if (isset ($ node-> stmts ) && is_array ($ node ->stmts )) {
149
+ if (property_exists ($ node, ' stmts ' ) && is_array ($ node ->stmts )) {
150
150
foreach ($ node ->stmts as $ stmt ) {
151
151
$ this ->postProcessNode ($ stmt );
152
152
}
@@ -202,9 +202,7 @@ private function generateAdditionalTagsFromDoc(Doc $docComment): array
202
202
203
203
try {
204
204
$ docblock = $ this ->docBlockFactory ->create ($ docCommentText );
205
- } catch (\RuntimeException $ e ) {
206
- return [];
207
- } catch (\InvalidArgumentException $ e ) {
205
+ } catch (\RuntimeException | \InvalidArgumentException $ e ) {
208
206
return [];
209
207
}
210
208
@@ -260,9 +258,7 @@ private function addTags(string $name, Doc $docComment): ?Doc
260
258
261
259
try {
262
260
$ docblock = $ this ->docBlockFactory ->create ($ docCommentText );
263
- } catch (\RuntimeException $ e ) {
264
- return null ;
265
- } catch (\InvalidArgumentException $ e ) {
261
+ } catch (\RuntimeException | \InvalidArgumentException $ e ) {
266
262
return null ;
267
263
}
268
264
@@ -430,7 +426,7 @@ static function (WordPressTag $tag) use ($matchNames): bool {
430
426
*/
431
427
private function getAdditionalTagsFromMap (string $ symbolName ): array
432
428
{
433
- if (! isset ( $ this ->functionMap ) ) {
429
+ if ($ this ->functionMap === null ) {
434
430
$ this ->functionMap = require sprintf ('%s/functionMap.php ' , dirname (__DIR__ ));
435
431
}
436
432
@@ -495,7 +491,7 @@ private function getAdditionFromParam(Param $tag): ?WordPressTag
495
491
$ tagVariableType = $ tag ->getType ();
496
492
497
493
// Skip if information we need is missing.
498
- if (! $ tagDescription instanceof Description || ! $ tagVariableName || ! $ tagVariableType instanceof Type) {
494
+ if (! $ tagDescription instanceof Description || $ tagVariableName === null || $ tagVariableName === '' || ! $ tagVariableType instanceof Type) {
499
495
return null ;
500
496
}
501
497
@@ -636,7 +632,7 @@ private static function getTypeNameFromDescriptionString(?string $tagDescription
636
632
*/
637
633
$ matched = preg_match ("#(?>returns|either|one of|accepts|values are|:) ('.+'),? (?>or|and) '([^']+)'#i " , $ fullDescription , $ matches );
638
634
639
- if (! $ matched ) {
635
+ if ($ matched !== 1 ) {
640
636
return null ;
641
637
}
642
638
@@ -805,7 +801,7 @@ private function voidOrNever(Node $node): string
805
801
$ this ->nodeFinder ->findFirst (
806
802
$ returnStmts ,
807
803
static function (Node $ node ): bool {
808
- return isset ($ node ->expr ) ;
804
+ return property_exists ($ node, ' expr ' ) && $ node ->expr !== null ;
809
805
}
810
806
) instanceof Node
811
807
) {
@@ -823,10 +819,11 @@ static function (Node $node): bool {
823
819
}
824
820
// If a first level statement is exit/die, it's return type never.
825
821
if ($ stmt ->expr instanceof Exit_) {
826
- if ($ stmt ->expr ->expr instanceof String_) {
827
- if (strpos ($ stmt ->expr ->expr ->value , 'must be overridden ' ) !== false ) {
828
- return '' ;
829
- }
822
+ if (! $ stmt ->expr ->expr instanceof String_) {
823
+ return 'never ' ;
824
+ }
825
+ if (strpos ($ stmt ->expr ->expr ->value , 'must be overridden ' ) !== false ) {
826
+ return '' ;
830
827
}
831
828
return 'never ' ;
832
829
}
@@ -859,13 +856,14 @@ static function (Node $node): bool {
859
856
if (is_int ($ arg )) {
860
857
return 'never ' ;
861
858
}
862
- if (is_array ($ arg )) {
863
- if (! isset ($ arg ['exit ' ]) || (bool )$ arg ['exit ' ] === true ) {
864
- return 'never ' ;
865
- }
859
+
860
+ if (! is_array ($ arg )) {
861
+ continue ;
866
862
}
867
863
868
- continue ;
864
+ if (! array_key_exists ('exit ' , $ arg ) || (bool )$ arg ['exit ' ]) {
865
+ return 'never ' ;
866
+ }
869
867
}
870
868
return '' ;
871
869
}
0 commit comments