@@ -233,6 +233,8 @@ private function coerceType($value, \ReflectionType $type)
233
233
return (string )$ value ;
234
234
case "array " :
235
235
return (array )$ value ;
236
+ case 'bool ' :
237
+ return is_bool ($ value ) ? $ value : StringHelper::equals ($ value , "true " , true );
236
238
default :
237
239
return $ value ;
238
240
@@ -253,6 +255,9 @@ private function coerceType($value, \ReflectionType $type)
253
255
public function mapObjectToArray ($ object , string $ prefix = "" )
254
256
{
255
257
if (!is_object ($ object )) {
258
+ if (is_bool ($ object )){
259
+ return $ object === true ? "true " : "false " ;
260
+ }
256
261
return $ object ;
257
262
}
258
263
if (get_class ($ object ) === \stdClass::class) {
@@ -298,7 +303,34 @@ private static function isOfValidType($value, $type)
298
303
299
304
private static function isOfCoercibleType ($ value , $ type ): bool
300
305
{
301
- return (($ type === "int " || $ type === "double " || $ type === "float " ) && is_numeric ($ value )) || ($ type === "bool " && is_bool ($ value ));
306
+ return (self ::isNumericType ($ type ) && is_numeric ($ value )) || ($ type === "bool " && self ::isBooleanValue ($ value ));
307
+ }
308
+
309
+ /**
310
+ * @param $value
311
+ * @return bool
312
+ */
313
+ private static function isBooleanStringValue ($ value ): bool
314
+ {
315
+ return is_string ($ value ) && StringHelper::equals ($ value , "true " , true ) || StringHelper::equals ($ value , "false " , true );
316
+ }
317
+
318
+ /**
319
+ * @param $value
320
+ * @return bool
321
+ */
322
+ private static function isBooleanValue ($ value ): bool
323
+ {
324
+ return is_bool ($ value ) || self ::isBooleanStringValue ($ value );
325
+ }
326
+
327
+ /**
328
+ * @param $type
329
+ * @return bool
330
+ */
331
+ private static function isNumericType ($ type ): bool
332
+ {
333
+ return $ type === "int " || $ type === "double " || $ type === "float " ;
302
334
}
303
335
304
336
private static function isCustomType (\ReflectionType $ propertyType )
0 commit comments