Iterators   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 55
ccs 0
cts 12
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A rewind() 0 3 1
A current() 0 3 1
A key() 0 3 1
A toArray() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\phpermutations;
6
7
use Countable;
8
9
abstract class Iterators extends Combinatorics implements Countable, IteratorInterface
10
{
11
    /**
12
     * A copy of the dataset at a give time.
13
     *
14
     * @var array<int, mixed>
15
     */
16
    protected $current;
17
18
    /**
19
     * @var int
20
     */
21
    protected $key = 0;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function current(): mixed
27
    {
28
        return $this->current;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function key(): int
35
    {
36
        return $this->key;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * @return void
43
     */
44
    public function rewind(): void
45
    {
46
        $this->key = 0;
47
    }
48
49
    /**
50
     * Convert the iterator into an array.
51
     *
52
     * @return array<int, mixed>
53
     *               The elements
54
     */
55
    public function toArray(): array
56
    {
57
        $data = [];
58
59
        for ($this->rewind(); $this->valid(); $this->next()) {
60
            $data[] = $this->current();
61
        }
62
63
        return $data;
64
    }
65
}
66