ArrayInput::reset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Maketok\DataMigration\Input;
4
5
class ArrayInput implements InputResourceInterface, \Iterator
6
{
7
    /**
8
     * @var array
9
     */
10
    private $entries = [];
11
    /**
12
     * @var int
13
     */
14
    private $index = 0;
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 2
    public function get()
20
    {
21 2
        if (!$this->valid()) {
22 2
            return false;
23
        }
24 2
        $current = $this->current();
25 2
        $this->next();
26 2
        return $current;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 3
    public function add(array $entity)
33
    {
34 3
        $this->entries[] = $entity;
35 3
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function reset()
41
    {
42 1
        $this->rewind();
43 1
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function current()
49
    {
50 2
        return $this->entries[$this->index];
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 3
    public function next()
57
    {
58 3
        $this->index += 1;
59 3
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 1
    public function key()
65
    {
66 1
        return $this->index;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 3
    public function valid()
73
    {
74 3
        return isset($this->entries[$this->index]);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 1
    public function rewind()
81
    {
82 1
        $this->index = 0;
83 1
    }
84
}
85