MapIterator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A current() 0 4 1
1
<?php
2
/**
3
 * An iterator that calls a map function for the current value.
4
 *
5
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
6
 * @copyright Copyright (c) 2009-2017 FluentDOM Contributors
7
 */
8
namespace FluentDOM\Utility\Iterators {
9
10
  /**
11
   * An iterator that calls a map function for the current value before returning it.
12
   */
13
  class MapIterator extends \IteratorIterator {
14
15
    protected $_position  = 0;
16
17
    /**
18
     * @var callable
19
     */
20
    private $_callback;
21
22
    /**
23
     * @param \Traversable $traversable
24
     * @param callable $callback
25
     */
26 1
    public function __construct(\Traversable $traversable, callable $callback) {
27 1
      parent::__construct($traversable);
28 1
      $this->_callback = $callback;
29 1
    }
30
31
    /**
32
     * @return mixed
33
     */
34 1
    public function current() {
35 1
      $callback = $this->_callback;
36 1
      return $callback(parent::current(), parent::key());
37
    }
38
  }
39
}
40