Passed
Push — master ( 1107f1...a96017 )
by Peter
34s
created

CollectionDto   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 39
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A count() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A offsetExists() 0 4 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
abstract class CollectionDto implements IteratorAggregate, Countable, ArrayAccess
11
{
12
    /**
13
     * @var array
14
     */
15
    public $items;
16
17 22
    protected function __construct(string $class, array $items)
18
    {
19 22
        Assert::allIsInstanceOf($items, $class);
20
21 22
        $this->items = $items;
22 22
    }
23
24 6
    public function count(): int
25
    {
26 6
        return count($this->items);
27
    }
28
29 1
    public function offsetExists($offset)
30
    {
31 1
        return array_key_exists($offset, $this->items);
32
    }
33
34 3
    public function offsetGet($offset)
35
    {
36 3
        return $this->items[$offset];
37
    }
38
39 1
    public function offsetSet($offset, $value)
40
    {
41 1
        $this->items[$offset] = $value;
42 1
    }
43
44 1
    public function offsetUnset($offset)
45
    {
46 1
        unset($this->items[$offset]);
47 1
    }
48
}
49