MapIterator::current()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * League.Csv (https://csv.thephpleague.com)
5
 *
6
 * (c) Ignace Nyamagana Butera <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace League\Csv;
15
16
use IteratorIterator;
17
use Traversable;
18
19
/**
20
 * Map value from an iterator before yielding.
21
 *
22
 * @internal used internally to modify CSV content
23
 */
24
class MapIterator extends IteratorIterator
25
{
26
    /**
27
     * The callback to apply on all InnerIterator current value.
28
     *
29
     * @var callable
30
     */
31
    protected $callable;
32
33
    /**
34
     * New instance.
35
     */
36 27
    public function __construct(Traversable $iterator, callable $callable)
37
    {
38 27
        parent::__construct($iterator);
39 27
        $this->callable = $callable;
40 27
    }
41
42
    /**
43
     * @return mixed The value of the current element.
44
     */
45 15
    public function current()
46
    {
47 15
        return ($this->callable)(parent::current(), $this->key());
48
    }
49
}
50