Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,35 @@ public function getIterator(): Traversable
return $iterator;
}

/**
* @param string $offset
*/
public function offsetExists(mixed $offset): bool
{
return isset($this->fields[$offset]);
}

/**
* @param string $offset
* @return true|Fields|null
*/
public function offsetGet(mixed $offset): mixed
{
return $this->fields[$offset];
return $this->fields[$offset] ?? null;
}

/**
* @param string $offset
* @param true|Fields $value
*/
public function offsetSet(mixed $offset, mixed $value): void
{
$this->fields[$offset] = $value;
}

/**
* @param string $offset
*/
public function offsetUnset(mixed $offset): void
{
unset($this->fields[$offset]);
Expand Down
16 changes: 16 additions & 0 deletions tests/FieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestStatus\Warning;

#[CoversClass(Fields::class)]
class FieldsTest extends TestCase
{
public function testArrayAccess(): void
{
$fields = new Fields();

$this->assertNull($fields['@id']);

$fields['@id'] = true;

$this->assertTrue($fields['@id']);

$fields['eventDate'] = new Fields();

$this->assertInstanceOf(Fields::class, $fields['eventDate']);
}

public function testKeys(): void
{
$fields = Fields::fromArray([
Expand Down