Passed
Push — main ( e48091...6c9276 )
by Anatoly
05:36 queued 13s
created

Collection::offsetSet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sunrise\Hydrator\Tests\Fixtures;
6
7
use ArrayAccess;
8
use OverflowException;
9
10
final class Collection implements ArrayAccess
11
{
12
    public array $elements = [];
13
14
    public function offsetExists($offset)
15
    {
16
        return isset($this->elements[$offset]);
17
    }
18
19
    public function offsetGet($offset)
20
    {
21
        return $this->elements[$offset] ?? null;
22
    }
23
24
    public function offsetSet($offset, $value)
25
    {
26
        if (!empty($this->elements)) {
27
            throw new OverflowException();
28
        }
29
30
        $this->elements[$offset] = $value;
31
    }
32
33
    public function offsetUnset($offset)
34
    {
35
        unset($this->elements[$offset]);
36
    }
37
}
38