CollectionDto::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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