Completed
Pull Request — master (#3)
by Peter
01:56
created

CollectionDto::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace PtrTn\Battlerite\Dto;
4
5
use ArrayAccess;
6
use Countable;
7
use IteratorAggregate;
8
use Webmozart\Assert\Assert;
9
10
abstract class CollectionDto implements IteratorAggregate, Countable, ArrayAccess
11
{
12
    /**
13
     * @var array
14
     */
15
    public $items;
16
17 11
    protected function __construct(string $class, array $items)
18
    {
19 11
        Assert::allIsInstanceOf($items, $class);
20
21 11
        $this->items = $items;
22 11
    }
23
24 2
    public function count(): int
25
    {
26 2
        return count($this->items);
27
    }
28
29
    public function offsetExists($offset)
30
    {
31
        return array_key_exists($offset, $this->items);
32
    }
33
34 1
    public function offsetGet($offset)
35
    {
36 1
        return $this->items[$offset];
37
    }
38
39
    public function offsetSet($offset, $value)
40
    {
41
        $this->items[$offset] = $value;
42
    }
43
44
    public function offsetUnset($offset)
45
    {
46
        unset($this->items[$offset]);
47
    }
48
}
49