@@ -94,12 +94,10 @@ public function enterNode(Node $node)
94
94
$ this ->additionalTagStrings [$ symbolName ] = $ additions ;
95
95
}
96
96
97
- if ($ voidOrNever !== '' ) {
97
+ if ($ voidOrNever instanceof Type ) {
98
98
$ addition = sprintf (
99
99
'@phpstan-return %s ' ,
100
- $ voidOrNever === 'never '
101
- ? (new Never_ ())->__toString ()
102
- : (new Void_ ())->__toString ()
100
+ $ voidOrNever ->__toString ()
103
101
);
104
102
if (
105
103
! isset ($ this ->additionalTagStrings [$ symbolName ])
@@ -786,15 +784,18 @@ private static function isOptional(string $description): bool
786
784
|| (stripos ($ description , 'Defaults to ' ) !== false );
787
785
}
788
786
789
- private function voidOrNever (Node $ node ): string
787
+ private function voidOrNever (Node $ node ): ? Type
790
788
{
789
+ $ never = new Never_ ();
790
+ $ void = new Void_ ();
791
+
791
792
if (! ($ node instanceof Function_) && ! ($ node instanceof ClassMethod)) {
792
- return '' ;
793
+ return null ;
793
794
}
794
795
795
796
if (! isset ($ node ->stmts ) || count ($ node ->stmts ) === 0 ) {
796
797
// Interfaces and abstract methods.
797
- return '' ;
798
+ return null ;
798
799
}
799
800
800
801
$ returnStmts = $ this ->nodeFinder ->findInstanceOf ($ node , Stmt_Return::class);
@@ -811,11 +812,11 @@ static function (Node $node): bool {
811
812
}
812
813
) instanceof Node
813
814
) {
814
- return '' ;
815
+ return null ;
815
816
}
816
817
// If there is no return statement that is not void,
817
818
// it's return type void.
818
- return ' void ' ;
819
+ return $ void ;
819
820
}
820
821
821
822
// Check for never return type.
@@ -826,12 +827,12 @@ static function (Node $node): bool {
826
827
// If a first level statement is exit/die, it's return type never.
827
828
if ($ stmt ->expr instanceof Exit_) {
828
829
if (! $ stmt ->expr ->expr instanceof String_) {
829
- return ' never ' ;
830
+ return $ never ;
830
831
}
831
832
if (strpos ($ stmt ->expr ->expr ->value , 'must be overridden ' ) !== false ) {
832
- return '' ;
833
+ return null ;
833
834
}
834
- return ' never ' ;
835
+ return $ never ;
835
836
}
836
837
if (! ($ stmt ->expr instanceof FuncCall) || ! ($ stmt ->expr ->name instanceof Name)) {
837
838
continue ;
@@ -840,7 +841,7 @@ static function (Node $node): bool {
840
841
// If a first level statement is a call to wp_send_json(_success/error),
841
842
// it's return type never.
842
843
if (strpos ($ name ->toString (), 'wp_send_json ' ) === 0 ) {
843
- return ' never ' ;
844
+ return $ never ;
844
845
}
845
846
// Skip all functions but wp_die().
846
847
if (strpos ($ name ->toString (), 'wp_die ' ) !== 0 ) {
@@ -849,7 +850,7 @@ static function (Node $node): bool {
849
850
$ args = $ stmt ->expr ->getArgs ();
850
851
// If wp_die is called without 3rd parameter, it's return type never.
851
852
if (count ($ args ) < 3 ) {
852
- return ' never ' ;
853
+ return $ never ;
853
854
}
854
855
// If wp_die is called with 3rd parameter, we need additional checks.
855
856
try {
@@ -860,18 +861,18 @@ static function (Node $node): bool {
860
861
}
861
862
862
863
if (is_int ($ arg )) {
863
- return ' never ' ;
864
+ return $ never ;
864
865
}
865
866
866
867
if (! is_array ($ arg )) {
867
868
continue ;
868
869
}
869
870
870
871
if (! array_key_exists ('exit ' , $ arg ) || (bool )$ arg ['exit ' ]) {
871
- return ' never ' ;
872
+ return $ never ;
872
873
}
873
874
}
874
- return '' ;
875
+ return null ;
875
876
}
876
877
877
878
private function getCleanCommentsNode (Node $ node ): Node
0 commit comments