Passed
Push — master ( a2fa16...8a4497 )
by Pol
11:27
created

Iterators::key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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