MapIterator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 30
c 0
b 0
f 0
wmc 2
lcom 1
cbo 0
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A current() 0 5 1
1
<?php
2
/**
3
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Helper;
15
16
use IteratorIterator;
17
use Traversable;
18
19
class MapIterator extends IteratorIterator
20
{
21
    /**
22
     * Function to apply to each iterated element
23
     *
24
     * @var callable
25
     */
26
    private $callable;
27
28
    /**
29
     * MapIterator constructor.
30
     *
31
     * @param Traversable $iterator
32
     * @param callable    $callable
33
     */
34 9
    public function __construct(Traversable $iterator, callable $callable)
35
    {
36 9
        parent::__construct($iterator);
37 9
        $this->callable = $callable;
38 9
    }
39
40
    /**
41
     * Get the value of the current element
42
     */
43 8
    public function current()
44
    {
45 8
        $iterator = $this->getInnerIterator();
46 8
        return call_user_func($this->callable, $iterator->current(), $iterator->key(), $iterator);
47
    }
48
}
49