IndexCollection::rewind()   A
last analyzed

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
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Xervice\Elasticsearch\Business\Collection;
5
6
use Xervice\Elasticsearch\Dependency\Plugin\IndexProviderInterface;
7
8
class IndexCollection implements \Iterator, \Countable
9
{
10
    /**
11
     * @var \Xervice\Elasticsearch\Dependency\Plugin\IndexProviderInterface[]
12
     */
13
    private $collection;
14
15
    /**
16
     * @var int
17
     */
18
    private $position;
19
20
    /**
21
     * Collection constructor.
22
     *
23
     * @param \Xervice\Elasticsearch\Dependency\Plugin\IndexProviderInterface[] $collection
24
     */
25 4
    public function __construct(array $collection)
26
    {
27 4
        foreach ($collection as $validator) {
28 3
            $this->add($validator);
29
        }
30 4
    }
31
32
    /**
33
     * @param \Xervice\Elasticsearch\Dependency\Plugin\IndexProviderInterface $validator
34
     */
35 3
    public function add(IndexProviderInterface $validator): void
36
    {
37 3
        $this->collection[] = $validator;
38 3
    }
39
40
    /**
41
     * @return \Xervice\Elasticsearch\Dependency\Plugin\IndexProviderInterface
42
     */
43 3
    public function current(): IndexProviderInterface
44
    {
45 3
        return $this->collection[$this->position];
46
    }
47
48 3
    public function next(): void
49
    {
50 3
        $this->position++;
51 3
    }
52
53
    /**
54
     * @return int
55
     */
56
    public function key(): int
57
    {
58
        return $this->position;
59
    }
60
61
    /**
62
     * @return bool
63
     */
64 4
    public function valid(): bool
65
    {
66 4
        return isset($this->collection[$this->position]);
67
    }
68
69 4
    public function rewind(): void
70
    {
71 4
        $this->position = 0;
72 4
    }
73
74
    /**
75
     * @return int
76
     */
77
    public function count(): int
78
    {
79
        return \count($this->collection);
80
    }
81
}