Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
TraitArrayAccess
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 offsetExists
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offsetGet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offsetSet
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 offsetUnset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3// ╔════════════════════════════════════════════════════════════╗
4// ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║
5// ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com>     ║
6// ╚════════════════════════════════════════════════════════════╝
7
8declare(strict_types=1);
9
10namespace Phexium\Domain\Collection\Trait;
11
12trait TraitArrayAccess
13{
14    public function offsetExists(mixed $offset): bool
15    {
16        return array_key_exists($offset, $this->collection);
17    }
18
19    public function offsetGet(mixed $offset): mixed
20    {
21        return $this->collection[$offset] ?? null;
22    }
23
24    public function offsetSet(mixed $offset, mixed $value): void
25    {
26        if ($offset === null) {
27            $this->collection[] = $value;
28        } else {
29            $this->collection[$offset] = $value;
30        }
31    }
32
33    public function offsetUnset(mixed $offset): void
34    {
35        unset($this->collection[$offset]);
36    }
37}