@@ -115,7 +115,7 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra
115
115
));
116
116
117
117
if (isset ($ a [$ prefix .'returnType ' ])) {
118
- $ a [$ prefix .'returnType ' ] = ( string ) $ a [$ prefix .'returnType ' ];
118
+ $ a [$ prefix .'returnType ' ] = method_exists ( ' ReflectionType ' , ' getName ' ) ? $ a [$ prefix .'returnType ' ]-> getName () : $ a [ $ prefix . ' returnType ' ]-> __toString () ;
119
119
}
120
120
if (isset ($ a [$ prefix .'this ' ])) {
121
121
$ a [$ prefix .'this ' ] = new CutStub ($ a [$ prefix .'this ' ]);
@@ -164,12 +164,13 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
164
164
'position ' => 'getPosition ' ,
165
165
'isVariadic ' => 'isVariadic ' ,
166
166
'byReference ' => 'isPassedByReference ' ,
167
+ 'allowsNull ' => 'allowsNull ' ,
167
168
));
168
169
169
170
try {
170
171
if (method_exists ($ c , 'hasType ' )) {
171
172
if ($ c ->hasType ()) {
172
- $ a [$ prefix .'typeHint ' ] = $ c ->getType ()->__toString ();
173
+ $ a [$ prefix .'typeHint ' ] = method_exists ( ' ReflectionType ' , ' getName ' ) ? $ c -> getType ()-> getName () : $ c ->getType ()->__toString ();
173
174
}
174
175
} else {
175
176
$ v = explode (' ' , $ c ->__toString (), 6 );
@@ -182,14 +183,20 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
182
183
$ a [$ prefix .'typeHint ' ] = $ m [1 ];
183
184
}
184
185
}
186
+ if (!isset ($ a [$ prefix .'typeHint ' ])) {
187
+ unset($ a [$ prefix .'allowsNull ' ]);
188
+ }
185
189
186
190
try {
187
191
$ a [$ prefix .'default ' ] = $ v = $ c ->getDefaultValue ();
188
192
if (method_exists ($ c , 'isDefaultValueConstant ' ) && $ c ->isDefaultValueConstant ()) {
189
193
$ a [$ prefix .'default ' ] = new ConstStub ($ c ->getDefaultValueConstantName (), $ v );
190
194
}
195
+ if (null === $ v ) {
196
+ unset($ a [$ prefix .'allowsNull ' ]);
197
+ }
191
198
} catch (\ReflectionException $ e ) {
192
- if (isset ($ a [$ prefix .'typeHint ' ]) && $ c ->allowsNull ()) {
199
+ if (isset ($ a [$ prefix .'typeHint ' ]) && $ c ->allowsNull () && ! method_exists ( ' ReflectionType ' , ' getName ' ) ) {
193
200
$ a [$ prefix .'default ' ] = null ;
194
201
}
195
202
}
0 commit comments