| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\PhpDocParser\Ast\PhpDoc; |
| 4: | |
| 5: | use PHPStan\PhpDocParser\Ast\NodeAttributes; |
| 6: | use PHPStan\PhpDocParser\Ast\Type\TypeNode; |
| 7: | use function trim; |
| 8: | |
| 9: | class TemplateTagValueNode implements PhpDocTagValueNode |
| 10: | { |
| 11: | |
| 12: | use NodeAttributes; |
| 13: | |
| 14: | |
| 15: | public string $name; |
| 16: | |
| 17: | public ?TypeNode $bound; |
| 18: | |
| 19: | public ?TypeNode $default; |
| 20: | |
| 21: | public ?TypeNode $lowerBound; |
| 22: | |
| 23: | |
| 24: | public string $description; |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | public function __construct(string $name, ?TypeNode $bound, string $description, ?TypeNode $default = null, ?TypeNode $lowerBound = null) |
| 30: | { |
| 31: | $this->name = $name; |
| 32: | $this->bound = $bound; |
| 33: | $this->lowerBound = $lowerBound; |
| 34: | $this->default = $default; |
| 35: | $this->description = $description; |
| 36: | } |
| 37: | |
| 38: | public function __toString(): string |
| 39: | { |
| 40: | $upperBound = $this->bound !== null ? " of {$this->bound}" : ''; |
| 41: | $lowerBound = $this->lowerBound !== null ? " super {$this->lowerBound}" : ''; |
| 42: | $default = $this->default !== null ? " = {$this->default}" : ''; |
| 43: | return trim("{$this->name}{$upperBound}{$lowerBound}{$default} {$this->description}"); |
| 44: | } |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | public static function __set_state(array $properties): self |
| 50: | { |
| 51: | $instance = new self($properties['name'], $properties['bound'], $properties['description'], $properties['default'] ?? null, $properties['lowerBound'] ?? null); |
| 52: | if (isset($properties['attributes'])) { |
| 53: | foreach ($properties['attributes'] as $key => $value) { |
| 54: | $instance->setAttribute($key, $value); |
| 55: | } |
| 56: | } |
| 57: | return $instance; |
| 58: | } |
| 59: | |
| 60: | } |
| 61: | |