1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\PhpDocParser\Ast\Type;
4:
5: use PHPStan\PhpDocParser\Ast\NodeAttributes;
6:
7: class NullableTypeNode implements TypeNode
8: {
9:
10: use NodeAttributes;
11:
12: public TypeNode $type;
13:
14: public function __construct(TypeNode $type)
15: {
16: $this->type = $type;
17: }
18:
19: public function __toString(): string
20: {
21: if ($this->type instanceof self) {
22: // "??Foo" is no type at all, so the one written inside keeps the
23: // parentheses it was read with
24: return '?(' . $this->type . ')';
25: }
26:
27: return '?' . $this->type;
28: }
29:
30: /**
31: * @param array<string, mixed> $properties
32: */
33: public static function __set_state(array $properties): self
34: {
35: $instance = new self($properties['type']);
36: if (isset($properties['attributes'])) {
37: foreach ($properties['attributes'] as $key => $value) {
38: $instance->setAttribute($key, $value);
39: }
40: }
41: return $instance;
42: }
43:
44: }
45: