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: /** @var IdentifierTypeNode */
15: public $identifier;
16:
17: /** @var TemplateTagValueNode[] */
18: public $templateTypes;
19:
20: /** @var CallableTypeParameterNode[] */
21: public $parameters;
22:
23: /** @var TypeNode */
24: public $returnType;
25:
26: /**
27: * @param CallableTypeParameterNode[] $parameters
28: * @param TemplateTagValueNode[] $templateTypes
29: */
30: public function __construct(IdentifierTypeNode $identifier, array $parameters, TypeNode $returnType, array $templateTypes = [])
31: {
32: $this->identifier = $identifier;
33: $this->parameters = $parameters;
34: $this->returnType = $returnType;
35: $this->templateTypes = $templateTypes;
36: }
37:
38:
39: public function __toString(): string
40: {
41: $returnType = $this->returnType;
42: if ($returnType instanceof self) {
43: $returnType = "({$returnType})";
44: }
45: $template = $this->templateTypes !== []
46: ? '<' . implode(', ', $this->templateTypes) . '>'
47: : '';
48: $parameters = implode(', ', $this->parameters);
49: return "{$this->identifier}{$template}({$parameters}): {$returnType}";
50: }
51:
52: }
53: