1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\PhpDocParser\Ast\Type;
4:
5: use PHPStan\PhpDocParser\Ast\NodeAttributes;
6:
7: /**
8: * A template declared in a generic type argument, like the "T of Foo" in
9: * class-string-map<T of Foo, T> or the "K of key-of<Config>" in
10: * array<K of key-of<Config>, Config[K]>.
11: *
12: * The template is scoped to the generic type it is declared in. The parser reads
13: * it in the arguments of every generic type; which types give it a meaning is up
14: * to the tool resolving the types.
15: */
16: class TemplateDeclarationTypeNode implements TypeNode
17: {
18:
19: use NodeAttributes;
20:
21: public string $name;
22:
23: public TypeNode $bound;
24:
25: public function __construct(string $name, TypeNode $bound)
26: {
27: $this->name = $name;
28: $this->bound = $bound;
29: }
30:
31: public function __toString(): string
32: {
33: return "{$this->name} of {$this->bound}";
34: }
35:
36: /**
37: * @param array<string, mixed> $properties
38: */
39: public static function __set_state(array $properties): self
40: {
41: $instance = new self($properties['name'], $properties['bound']);
42: if (isset($properties['attributes'])) {
43: foreach ($properties['attributes'] as $key => $value) {
44: $instance->setAttribute($key, $value);
45: }
46: }
47: return $instance;
48: }
49:
50: }
51: