3 declare(strict_types=1);
5 namespace CuyZ\Valinor\Definition\Repository\Cache\Compiler;
7 use CuyZ\Valinor\Definition\MethodDefinition;
8 use CuyZ\Valinor\Definition\ParameterDefinition;
10 use function var_export;
13 final class MethodDefinitionCompiler
15 private TypeCompiler $typeCompiler;
17 private ParameterDefinitionCompiler $parameterCompiler;
19 public function __construct(TypeCompiler $typeCompiler, AttributesCompiler $attributesCompiler)
21 $this->typeCompiler = $typeCompiler;
22 $this->parameterCompiler = new ParameterDefinitionCompiler($typeCompiler, $attributesCompiler);
25 public function compile(MethodDefinition $method): string
27 $parameters = array_map(
28 fn (ParameterDefinition $parameter) => $this->parameterCompiler->compile($parameter),
29 iterator_to_array($method->parameters())
32 $parameters = implode(', ', $parameters);
33 $isStatic = var_export($method->isStatic(), true);
34 $isPublic = var_export($method->isPublic(), true);
35 $returnType = $this->typeCompiler->compile($method->returnType());
38 new \CuyZ\Valinor\Definition\MethodDefinition(
40 '{$method->signature()}',
41 new \CuyZ\Valinor\Definition\Parameters($parameters),