| 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: | |