CollectionDto   A
last analyzed

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 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
/**
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