Passed
Push — master ( 653498...1099cb )
by Patrick
03:08
created

ActivityDtoCollection   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 53.33%

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 63
rs 10
ccs 16
cts 30
cp 0.5333
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetExists() 0 2 1
A __construct() 0 4 1
A current() 0 3 1
A offsetSet() 0 5 2
A merge() 0 3 1
A offsetGet() 0 2 1
A offsetUnset() 0 2 1
A key() 0 3 1
A valid() 0 3 1
A next() 0 3 1
A rewind() 0 3 1
1
<?php
2
3
namespace ForecastAutomation\Activity\Shared\Dto;
4
5
use ArrayAccess;
6
use Iterator;
7
8
class ActivityDtoCollection implements Iterator, ArrayAccess
9
{
10
    /**
11
     * @var \ForecastAutomation\Activity\Shared\Dto\ActivityDto[]
12
     */
13
    private array $activityDtos;
14
15
    private int $position = 0;
16
17 2
    public function __construct(
18
        ActivityDto ...$activityDtos
19
    ) {
20 2
        $this->activityDtos = $activityDtos;
21 2
    }
22
23 2
    public function current(): ActivityDto
24
    {
25 2
        return $this->activityDtos[$this->position];
26
    }
27
28 1
    public function next(): void
29
    {
30 1
        ++$this->position;
31 1
    }
32
33
    public function key(): int
34
    {
35
        return $this->position;
36
    }
37
38 1
    public function valid(): bool
39
    {
40 1
        return array_key_exists($this->position, $this->activityDtos);
41
    }
42
43 1
    public function rewind(): void
44
    {
45 1
        $this->position = 0;
46 1
    }
47
48
    public function offsetExists($offset): bool {
49
        return array_key_exists($offset, $this->activityDtos);
50
    }
51
52
    public function offsetGet($offset): mixed {
53
        return $this->array[$offset] ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property array does not exist on ForecastAutomation\Activ...o\ActivityDtoCollection. Did you maybe forget to declare it?
Loading history...
54
    }
55
56
    public function offsetSet($offset, $value): void {
57
        if (is_null($offset)) {
58
            $this->activityDtos[] = $value;
59
        } else {
60
            $this->activityDtos[$offset] = $value;
61
        }
62
    }
63
64
    public function offsetUnset($offset): void {
65
        unset($this->activityDtos[$offset]);
66
    }
67
68 1
    public function merge(ActivityDtoCollection $collection): ActivityDtoCollection {
69 1
        $this->activityDtos = array_merge($this->activityDtos, $collection->activityDtos);
70 1
        return $this;
71
    }
72
}
73