1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\PhpDocParser\Ast\Type;
4:
5: use PHPStan\PhpDocParser\Ast\NodeAttributes;
6: use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
7: use function implode;
8:
9: class CallableTypeNode implements TypeNode
10: {
11:
12: use NodeAttributes;
13:
14: public IdentifierTypeNode $identifier;
15:
16: /** @var TemplateTagValueNode[] */
17: public array $templateTypes;
18:
19: /** @var CallableTypeParameterNode[] */
20: public array $parameters;
21:
22: public TypeNode $returnType;
23:
24: /**
25: * @param CallableTypeParameterNode[] $parameters
26: * @param TemplateTagValueNode[] $templateTypes
27: */
28: public function __construct(IdentifierTypeNode $identifier, array $parameters, TypeNode $returnType, array $templateTypes)
29: {
30: $this->identifier = $identifier;
31: $this->parameters = $parameters;
32: $this->returnType = $returnType;
33: $this->templateTypes = $templateTypes;
34: }
35:
36:
37: public function __toString(): string
38: {
39: $returnType = $this->returnType;
40: if ($returnType instanceof self) {
41: $returnType = "({$returnType})";
42: }
43: $template = $this->templateTypes !== []
44: ? '<' . implode(', ', $this->templateTypes) . '>'
45: : '';
46: $parameters = implode(', ', $this->parameters);
47: return "{$this->identifier}{$template}({$parameters}): {$returnType}";
48: }
49:
50: }
51: