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

ActivityDtoCollection::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 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