@@ -61,29 +61,49 @@ public function __construct(string $data, bool $writeOnly = false)
61
61
/** @var int $count */
62
62
$ count = \count ($ returnTypes );
63
63
if ($ count === 0 ) {
64
- throw new \ RuntimeException ( ' Error when trying to extract parameter type ' ) ;
64
+ $ returnType = '' ;
65
65
}
66
66
foreach ($ returnTypes as &$ returnType ) {
67
67
$ pos = \strpos ($ returnType , '? ' );
68
68
if ($ pos !== false ) {
69
69
$ nullable = true ;
70
70
$ returnType = \str_replace ('? ' , '' , $ returnType );
71
71
}
72
- //remove the parenthesis only if we are not dealing with a callable
73
- if (\strpos ($ returnType , 'callable ' ) === false ) {
72
+ // remove the parenthesis only if we are not dealing with a callable
73
+ if (! str_contains ($ returnType , 'callable ' )) {
74
74
$ returnType = \str_replace (['( ' , ') ' ], '' , $ returnType );
75
75
}
76
- //here we deal with some weird phpstan typings
77
- if ($ returnType === 'non-empty-string ' ) {
76
+
77
+ // here we deal with some weird phpstan typings
78
+ if (str_contains ($ returnType , 'non-falsy-string ' )) {
78
79
$ returnType = 'string ' ;
79
- } elseif ($ returnType === 'positive-int ' ) {
80
+ }
81
+
82
+ if (str_contains ($ returnType , 'non-empty-string ' )) {
83
+ $ returnType = 'string ' ;
84
+ }
85
+
86
+ if (str_contains ($ returnType , '__stringAndStringable ' )) {
87
+ $ returnType = 'string ' ;
88
+ }
89
+
90
+ if ($ returnType === 'positive-int ' ) {
80
91
$ returnType = 'int ' ;
81
92
} elseif (is_numeric ($ returnType )) {
82
93
$ returnType = 'int ' ;
83
94
}
84
- if (\strpos ($ returnType , 'list< ' ) !== false ) {
95
+ if (str_contains ($ returnType , 'list< ' )) {
85
96
$ returnType = \str_replace ('list ' , 'array ' , $ returnType );
86
97
}
98
+
99
+ if (str_contains ($ returnType , 'int< ' )) {
100
+ $ returnType = 'int ' ;
101
+ }
102
+
103
+ if (\preg_match ('/__benevolent\<(.*)\>/ ' , $ returnType , $ regs )) {
104
+ $ returnType = $ regs [1 ];
105
+ }
106
+
87
107
$ returnType = Type::toRootNamespace ($ returnType );
88
108
}
89
109
$ this ->types = array_unique ($ returnTypes );
@@ -116,7 +136,7 @@ public function getSignatureType(?int $errorType = null): string
116
136
$ falsable = $ errorType === Method::FALSY_TYPE ? false : $ this ->falsable ;
117
137
$ types = $ this ->types ;
118
138
//no typehint exists for thoses cases
119
- if (\array_intersect (self ::NO_SIGNATURE_TYPES , $ types )) {
139
+ if (\array_intersect (self ::NO_SIGNATURE_TYPES , $ types ) !== [] ) {
120
140
return '' ;
121
141
}
122
142
@@ -137,12 +157,14 @@ public function getSignatureType(?int $errorType = null): string
137
157
//if there are several distinct types, no typehint (we use distinct in case doc block contains several times the same type, for example array<int>|array<string>)
138
158
if (count (array_unique ($ types )) > 1 ) {
139
159
return '' ;
140
- } elseif (\in_array ('void ' , $ types ) || (count ($ types ) === 0 && !$ nullable && !$ falsable )) {
160
+ }
161
+
162
+ if (\in_array ('void ' , $ types ) || ($ types === [] && !$ nullable && !$ falsable )) {
141
163
return 'void ' ;
142
164
}
143
165
144
166
145
- $ finalType = $ types [0 ];
167
+ $ finalType = $ types [0 ] ?? '' ;
146
168
if ($ finalType === 'bool ' && !$ nullable && $ errorType === Method::FALSY_TYPE ) {
147
169
// If the function only returns a boolean, since false is for error, true is for success.
148
170
// Let's replace this with a "void".
0 commit comments