Completed
Pull Request — master (#3)
by Peter
05:52 queued 01:20
created

CollectionDto   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 39
ccs 14
cts 16
cp 0.875
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 offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 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 20
    protected function __construct(string $class, array $items)
18
    {
19 20
        Assert::allIsInstanceOf($items, $class);
20
21 20
        $this->items = $items;
22 20
    }
23
24 5
    public function count(): int
25
    {
26 5
        return count($this->items);
27
    }
28
29
    public function offsetExists($offset)
30
    {
31
        return array_key_exists($offset, $this->items);
32
    }
33
34 2
    public function offsetGet($offset)
35
    {
36 2
        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