@@ -18,24 +18,33 @@ class CallbackTransformer implements DataTransformerInterface
18
18
{
19
19
/**
20
20
* The callback used for forward transform
21
- * @var \Closure
21
+ * @var callable
22
22
*/
23
23
private $ transform ;
24
24
25
25
/**
26
26
* The callback used for reverse transform
27
- * @var \Closure
27
+ * @var callable
28
28
*/
29
29
private $ reverseTransform ;
30
30
31
31
/**
32
32
* Constructor.
33
33
*
34
- * @param \Closure $transform The forward transform callback
35
- * @param \Closure $reverseTransform The reverse transform callback
34
+ * @param callable $transform The forward transform callback
35
+ * @param callable $reverseTransform The reverse transform callback
36
+ *
37
+ * @throws \InvalidArgumentException when the given callbacks is invalid
36
38
*/
37
- public function __construct (\ Closure $ transform , \ Closure $ reverseTransform )
39
+ public function __construct ($ transform , $ reverseTransform )
38
40
{
41
+ if (!is_callable ($ transform )) {
42
+ throw new \InvalidArgumentException ('Argument 1 should be a callable ' );
43
+ }
44
+ if (!is_callable ($ reverseTransform )) {
45
+ throw new \InvalidArgumentException ('Argument 2 should be a callable ' );
46
+ }
47
+
39
48
$ this ->transform = $ transform ;
40
49
$ this ->reverseTransform = $ reverseTransform ;
41
50
}
@@ -47,7 +56,7 @@ public function __construct(\Closure $transform, \Closure $reverseTransform)
47
56
*
48
57
* @return mixed The value in the transformed representation
49
58
*
50
- * @throws UnexpectedTypeException when the argument is not a string
59
+ * @throws UnexpectedTypeException when the argument is not of the expected type
51
60
* @throws TransformationFailedException when the transformation fails
52
61
*/
53
62
public function transform ($ data )
0 commit comments