| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\PhpDocParser\Ast\Type; |
| 4: | |
| 5: | use PHPStan\PhpDocParser\Ast\NodeAttributes; |
| 6: | |
| 7: | class OffsetAccessTypeNode implements TypeNode |
| 8: | { |
| 9: | |
| 10: | use NodeAttributes; |
| 11: | |
| 12: | public TypeNode $type; |
| 13: | |
| 14: | public TypeNode $offset; |
| 15: | |
| 16: | public function __construct(TypeNode $type, TypeNode $offset) |
| 17: | { |
| 18: | $this->type = $type; |
| 19: | $this->offset = $offset; |
| 20: | } |
| 21: | |
| 22: | public function __toString(): string |
| 23: | { |
| 24: | if ( |
| 25: | $this->type instanceof CallableTypeNode |
| 26: | || $this->type instanceof NullableTypeNode |
| 27: | ) { |
| 28: | return '(' . $this->type . ')[' . $this->offset . ']'; |
| 29: | } |
| 30: | |
| 31: | return $this->type . '[' . $this->offset . ']'; |
| 32: | } |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | public static function __set_state(array $properties): self |
| 38: | { |
| 39: | $instance = new self($properties['type'], $properties['offset']); |
| 40: | if (isset($properties['attributes'])) { |
| 41: | foreach ($properties['attributes'] as $key => $value) { |
| 42: | $instance->setAttribute($key, $value); |
| 43: | } |
| 44: | } |
| 45: | return $instance; |
| 46: | } |
| 47: | |
| 48: | } |
| 49: | |