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

MapIterator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A current() 0 6 1
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
 * Iterator to apply a callable on the elements of an Iterator
20
 *
21
 * @package League.csv
22
 * @since  3.3.0
23
 * @internal used internally to modify Iterator content
24
 */
25
class MapIterator extends IteratorIterator
26
{
27
    /**
28
     * The function to be apply on all InnerIterator element
29
     *
30
     * @var callable
31
     */
32
    private $callable;
33
34
    /**
35
     * Create a map iterator from another iterator
36
     *
37
     * @param Iterator $iterator the iterator to run through the callable function
38
     * @param callable $callable callable to run for each element in the Iterator
39
     */
40
    public function __construct(Iterator $iterator, callable $callable)
41
    {
42
        parent::__construct($iterator);
43
        $this->callable = $callable;
44
    }
45
46
    /**
47
     * Get the value of the current element
48
     */
49
    public function current()
50
    {
51
        $iterator = $this->getInnerIterator();
52
53
        return call_user_func($this->callable, $iterator->current(), $iterator->key(), $iterator);
54
    }
55
}
56