Repository navigation
Expand file tree
/
Copy pathCallableTypeNode.php
More file actions
65 lines (53 loc) · 1.71 KB
/
Copy pathCallableTypeNode.php
File metadata and controls
65 lines (53 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php declare(strict_types = 1);
namespace PHPStan\PhpDocParser\Ast\Type;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
use function implode;
class CallableTypeNode implements TypeNode
{
use NodeAttributes;
/** @var IdentifierTypeNode|NameNode */
public TypeNode $identifier;
/** @var TemplateTagValueNode[] */
public array $templateTypes;
/** @var CallableTypeParameterNode[] */
public array $parameters;
public TypeNode $returnType;
/**
* @param IdentifierTypeNode|NameNode $identifier
* @param CallableTypeParameterNode[] $parameters
* @param TemplateTagValueNode[] $templateTypes
*/
public function __construct(TypeNode $identifier, array $parameters, TypeNode $returnType, array $templateTypes)
{
$this->identifier = $identifier;
$this->parameters = $parameters;
$this->returnType = $returnType;
$this->templateTypes = $templateTypes;
}
public function __toString(): string
{
$returnType = $this->returnType;
if ($returnType instanceof self) {
$returnType = "({$returnType})";
}
$template = $this->templateTypes !== []
? '<' . implode(', ', $this->templateTypes) . '>'
: '';
$parameters = implode(', ', $this->parameters);
return "{$this->identifier}{$template}({$parameters}): {$returnType}";
}
/**
* @param array<string, mixed> $properties
*/
public static function __set_state(array $properties): self
{
$instance = new self($properties['identifier'], $properties['parameters'], $properties['returnType'], $properties['templateTypes']);
if (isset($properties['attributes'])) {
foreach ($properties['attributes'] as $key => $value) {
$instance->setAttribute($key, $value);
}
}
return $instance;
}
}