Skip to content

Commit

Permalink
fix: allow docblock for transformer callable type
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod authored Jul 19, 2024
1 parent b1017ce commit 69e0e3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Normalizer/Transformer/ValueTransformersHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
17 changes: 17 additions & 0 deletions tests/Integration/Normalizer/NormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 69e0e3a

Please sign in to comment.