@@ -241,21 +241,64 @@ public static function validateTypes(array $options, array $acceptedTypes)
241
241
}
242
242
}
243
243
244
- $ printableValue = is_object ($ value )
245
- ? get_class ($ value )
246
- : (is_array ($ value )
247
- ? 'Array '
248
- : (string ) $ value );
249
-
250
244
throw new InvalidOptionsException (sprintf (
251
245
'The option "%s" with value "%s" is expected to be of type "%s" ' ,
252
246
$ option ,
253
- $ printableValue ,
254
- implode ('", " ' , $ optionTypes )
247
+ self :: createPrintableValue ( $ value ) ,
248
+ implode ('", " ' , array_map ( function ( $ optionType ) { return self :: createPrintableType ( $ optionType ); }, $ optionTypes) )
255
249
));
256
250
}
257
251
}
258
252
253
+ /**
254
+ * Attempts to convert a given value into a (short) string or integer.
255
+ *
256
+ * @param mixed $value The value to convert.
257
+ *
258
+ * @return string The printable value.
259
+ */
260
+ private static function createPrintableValue ($ value )
261
+ {
262
+ if (is_object ($ value )) {
263
+ return get_class ($ value );
264
+ }
265
+
266
+ if (is_array ($ value )) {
267
+ return 'Array ' ;
268
+ }
269
+
270
+ if (null === $ value ) {
271
+ return 'null ' ;
272
+ }
273
+
274
+ if (is_string ($ value )) {
275
+ return '" ' .$ value .'" ' ;
276
+ }
277
+
278
+ if (is_bool ($ value )) {
279
+ return (string ) var_export ($ value , true );
280
+ }
281
+
282
+ return (string ) $ value ;
283
+ }
284
+
285
+ /**
286
+ * Attempts to convert a given value's type into a printable string.
287
+ *
288
+ * @param mixed $value The value to convert.
289
+ *
290
+ * @return string Objects get returned as their classname,
291
+ * all other values are put through gettype().
292
+ */
293
+ private static function createPrintableType ($ value )
294
+ {
295
+ if (is_object ($ value )) {
296
+ return get_class ($ value );
297
+ } else {
298
+ return gettype ($ value );
299
+ }
300
+ }
301
+
259
302
/**
260
303
* Validates that the given option values match the accepted values and
261
304
* throws an exception otherwise.
0 commit comments