diff --git a/src/Normalizer/Transformer/ValueTransformersHandler.php b/src/Normalizer/Transformer/ValueTransformersHandler.php index d5cdf90a..ef42b56c 100644 --- a/src/Normalizer/Transformer/ValueTransformersHandler.php +++ b/src/Normalizer/Transformer/ValueTransformersHandler.php @@ -118,8 +118,8 @@ private function checkTransformer(MethodDefinition|FunctionDefinition $method): throw new TransformerHasTooManyParameters($method); } - if ($parameters->count() > 1 && ! $parameters->at(1)->type instanceof CallableType) { - throw new TransformerHasInvalidCallableParameter($method, $parameters->at(1)->type); + if ($parameters->count() > 1 && ! $parameters->at(1)->nativeType instanceof CallableType) { + throw new TransformerHasInvalidCallableParameter($method, $parameters->at(1)->nativeType); } } } diff --git a/tests/Integration/Normalizer/NormalizerTest.php b/tests/Integration/Normalizer/NormalizerTest.php index 7f3183fc..15a0ad55 100644 --- a/tests/Integration/Normalizer/NormalizerTest.php +++ b/tests/Integration/Normalizer/NormalizerTest.php @@ -979,6 +979,23 @@ public function test_second_param_in_transformer_is_not_callable_throws_exceptio ->normalize(new stdClass()); } + public function test_second_param_in_transformer_is_callable_with_phpdoc_spec_does_not_throw(): void + { + $class = new class () { + /** @param callable():mixed $next */ + public function __invoke(stdClass $object, callable $next): int + { + return 42; + } + }; + $this->mapperBuilder() + ->registerTransformer($class) + ->normalizer(Format::array()) + ->normalize(new stdClass()); + + self::addToAssertionCount(1); + } + public function test_no_param_in_transformer_attribute_throws_exception(): void { $this->expectException(TransformerHasNoParameter::class);