b0c62e233b9c42c188d2c1dd4702afdbafb5d689
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 declare(strict_types=1);
4
5 namespace CuyZ\Valinor\Definition\Repository\Reflection;
6
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;
11 use ReflectionMethod;
12 use ReflectionParameter;
13
14 use function array_map;
15
16 /** @internal */
17 final class ReflectionMethodDefinitionBuilder
18 {
19 private ReflectionParameterDefinitionBuilder $parameterBuilder;
20
21 public function __construct(AttributesRepository $attributesRepository)
22 {
23 $this->parameterBuilder = new ReflectionParameterDefinitionBuilder($attributesRepository);
24 }
25
26 public function for(ReflectionMethod $reflection, ReflectionTypeResolver $typeResolver): MethodDefinition
27 {
28 $parameters = array_map(
29 fn (ReflectionParameter $parameter) => $this->parameterBuilder->for($parameter, $typeResolver),
30 $reflection->getParameters()
31 );
32
33 $returnType = $typeResolver->resolveType($reflection);
34
35 return new MethodDefinition(
36 $reflection->name,
37 Reflection::signature($reflection),
38 new Parameters(...$parameters),
39 $reflection->isStatic(),
40 $reflection->isPublic(),
41 $returnType
42 );
43 }
44 }