Skip to content

Commit 493d736

Browse files
committed
Add ArrayAccess support of the DocBlock object
1 parent dafd99a commit 493d736

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Diff for: src/DocBlock.php

+26-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
use TypeLang\PHPDoc\Tag\TagProviderInterface;
1111

1212
/**
13-
* @template-implements \IteratorAggregate<array-key, Tag>
13+
* @template-implements \IteratorAggregate<int<0, max>, Tag>
14+
* @template-implements \ArrayAccess<int<0, max>, Tag|null>
1415
*/
15-
final class DocBlock implements TagProviderInterface, \IteratorAggregate
16+
final class DocBlock implements
17+
TagProviderInterface,
18+
\IteratorAggregate,
19+
\ArrayAccess
1620
{
1721
use TagProvider;
1822

@@ -26,6 +30,26 @@ public function __construct(
2630
$this->bootTagProvider($tags);
2731
}
2832

33+
public function offsetExists(mixed $offset): bool
34+
{
35+
return isset($this->tags[$offset]);
36+
}
37+
38+
public function offsetGet(mixed $offset): ?Tag
39+
{
40+
return $this->tags[$offset] ?? null;
41+
}
42+
43+
public function offsetSet(mixed $offset, mixed $value): void
44+
{
45+
throw new \BadMethodCallException(self::class . ' objects are immutable');
46+
}
47+
48+
public function offsetUnset(mixed $offset): void
49+
{
50+
throw new \BadMethodCallException(self::class . ' objects are immutable');
51+
}
52+
2953
public function getDescription(): Description
3054
{
3155
return $this->description;

0 commit comments

Comments
 (0)