3 declare(strict_types=1);
5 namespace CuyZ\Valinor\Definition\Repository\Reflection;
7 use CuyZ\Valinor\Definition\MethodDefinition;
8 use CuyZ\Valinor\Definition\Parameters;
9 use CuyZ\Valinor\Definition\Repository\AttributesRepository;
10 use CuyZ\Valinor\Utility\Reflection\Reflection;
12 use ReflectionParameter;
14 use function array_map;
17 final class ReflectionMethodDefinitionBuilder
19 private ReflectionParameterDefinitionBuilder $parameterBuilder;
21 public function __construct(AttributesRepository $attributesRepository)
23 $this->parameterBuilder = new ReflectionParameterDefinitionBuilder($attributesRepository);
26 public function for(ReflectionMethod $reflection, ReflectionTypeResolver $typeResolver): MethodDefinition
28 $parameters = array_map(
29 fn (ReflectionParameter $parameter) => $this->parameterBuilder->for($parameter, $typeResolver),
30 $reflection->getParameters()
33 $returnType = $typeResolver->resolveType($reflection);
35 return new MethodDefinition(
37 Reflection::signature($reflection),
38 new Parameters(...$parameters),
39 $reflection->isStatic(),
40 $reflection->isPublic(),