Completed
Push — master ( 2c9a0d...3a6f86 )
by Márk
01:57
created

CallbackIterator::current()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Indigo\Iterator;
4
5
/**
6
 * Pass callbacks as iterator methods.
7
 *
8
 * @author Márk Sági-Kazár <[email protected]>
9
 */
10
class CallbackIterator implements \Iterator
11
{
12
    /**
13
     * @var callable
14
     */
15
    protected $current;
16
17
    /**
18
     * @var callable
19
     */
20
    protected $next;
21
22
    /**
23
     * @var callable
24
     */
25
    protected $key;
26
27
    /**
28
     * @var callable
29
     */
30
    protected $valid;
31
32
    /**
33
     * @var callable
34
     */
35
    protected $rewind;
36
37
    /**
38
     * @param callable $current
39
     * @param callable $next
40
     * @param callable $key
41
     * @param callable $valid
42
     * @param callable $rewind
43
     */
44 1
    public function __construct(
45
        callable $current,
46
        callable $next,
47
        callable $key,
48
        callable $valid,
49
        callable $rewind
50
    ) {
51 1
        $this->current = $current;
52 1
        $this->next = $next;
53 1
        $this->key = $key;
54 1
        $this->valid = $valid;
55 1
        $this->rewind = $rewind;
56 1
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 1
    public function current()
62
    {
63 1
        return call_user_func($this->current);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 1
    public function next()
70
    {
71 1
        call_user_func($this->next);
72 1
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 1
    public function key()
78
    {
79 1
        return call_user_func($this->key);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 1
    public function valid()
86
    {
87 1
        return call_user_func($this->valid);
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93 1
    public function rewind()
94
    {
95 1
        call_user_func($this->rewind);
96 1
    }
97
}
98