1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\PhpDoc\Tag;
4:
5: use PHPStan\Turbo\ReferencedByTurboExtension;
6: use PHPStan\Type\Generic\TemplateTypeVariance;
7: use PHPStan\Type\Type;
8:
9: /**
10: * @api
11: */
12: #[ReferencedByTurboExtension(key: 'templateTag')]
13: final class TemplateTag
14: {
15:
16: /**
17: * @param non-empty-string $name
18: * @param non-empty-list<non-empty-string>|null $circularBoundPath
19: * @param non-empty-list<non-empty-string>|null $circularDefaultPath
20: */
21: public function __construct(
22: private string $name,
23: private Type $bound,
24: private ?Type $default,
25: private TemplateTypeVariance $variance,
26: private ?array $circularBoundPath = null,
27: private ?array $circularDefaultPath = null,
28: )
29: {
30: }
31:
32: /**
33: * @return non-empty-string
34: */
35: public function getName(): string
36: {
37: return $this->name;
38: }
39:
40: public function getBound(): Type
41: {
42: return $this->bound;
43: }
44:
45: public function getDefault(): ?Type
46: {
47: return $this->default;
48: }
49:
50: public function getVariance(): TemplateTypeVariance
51: {
52: return $this->variance;
53: }
54:
55: /**
56: * The templates the written bound leads through back to this one, e.g. [A, B, A]
57: * for `@template A of B` and `@template B of A`. The bound is then mixed.
58: *
59: * @return non-empty-list<non-empty-string>|null
60: */
61: public function getCircularBoundPath(): ?array
62: {
63: return $this->circularBoundPath;
64: }
65:
66: /**
67: * Like getCircularBoundPath() for the default, which is then null.
68: *
69: * @return non-empty-list<non-empty-string>|null
70: */
71: public function getCircularDefaultPath(): ?array
72: {
73: return $this->circularDefaultPath;
74: }
75:
76: }
77: