Iterators::key()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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