Completed
Pull Request — master (#178)
by ignace nyamagana
02:34
created

MapIterator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
/**
3
* This file is part of the League.csv library
4
*
5
* @license http://opensource.org/licenses/MIT
6
* @link https://github.com/thephpleague/csv/
7
* @version 9.0.0
8
* @package League.csv
9
*
10
* For the full copyright and license information, please view the LICENSE
11
* file that was distributed with this source code.
12
*/
13
namespace League\Csv;
14
15
use Iterator;
16
use IteratorIterator;
17
18
/**
19
 * A MapIterator to apply a callable on an Iterator
20
 *
21
 * @package League.csv
22
 * @since  3.3.0
23
 * @internal used internally to modify Iterator content
24
 *
25
 */
26
class MapIterator extends IteratorIterator
27
{
28
    /**
29
     * The function to be apply on all InnerIterator element
30
     *
31
     * @var callable
32
     */
33
    private $callable;
34
35
    /**
36
     * The Constructor
37
     *
38
     * @param Iterator $iterator
39
     * @param callable $callable
40
     */
41
    public function __construct(Iterator $iterator, callable $callable)
42
    {
43
        parent::__construct($iterator);
44
        $this->callable = $callable;
45
    }
46
47
    /**
48
     * Get the value of the current element
49
     */
50
    public function current()
51
    {
52
        $iterator = $this->getInnerIterator();
53
54
        return call_user_func($this->callable, $iterator->current(), $iterator->key(), $iterator);
55
    }
56
}
57