| 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: | |
| 17: | public array $templateTypes; |
| 18: | |
| 19: | |
| 20: | public array $parameters; |
| 21: | |
| 22: | public TypeNode $returnType; |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 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: | public function __toString(): string |
| 37: | { |
| 38: | $returnType = $this->returnType; |
| 39: | if ($returnType instanceof self) { |
| 40: | $returnType = "({$returnType})"; |
| 41: | } |
| 42: | $template = $this->templateTypes !== [] |
| 43: | ? '<' . implode(', ', $this->templateTypes) . '>' |
| 44: | : ''; |
| 45: | $parameters = implode(', ', $this->parameters); |
| 46: | return "{$this->identifier}{$template}({$parameters}): {$returnType}"; |
| 47: | } |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | public static function __set_state(array $properties): self |
| 53: | { |
| 54: | $instance = new self($properties['identifier'], $properties['parameters'], $properties['returnType'], $properties['templateTypes']); |
| 55: | if (isset($properties['attributes'])) { |
| 56: | foreach ($properties['attributes'] as $key => $value) { |
| 57: | $instance->setAttribute($key, $value); |
| 58: | } |
| 59: | } |
| 60: | return $instance; |
| 61: | } |
| 62: | |
| 63: | } |
| 64: | |