Passed
Push — master ( 9e9b54...8c04f5 )
by
unknown
38s
created

MapByIterator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A key() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Itertools\lib;
8
9
use Zicht\Itertools\lib\Interfaces\FiniteIterableInterface;
10
use Zicht\Itertools\lib\Traits\FiniteIterableTrait;
11
12
/**
13
 * Class MapByIterator
14
 *
15
 * @package Zicht\Itertools\lib
16
 */
17 View Code Duplication
class MapByIterator extends \IteratorIterator implements FiniteIterableInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
{
19
    use FiniteIterableTrait;
20
21
    /**
22
     * @var callable
23
     */
24
    private $func;
25
26
    /**
27
     * MapByIterator constructor.
28
     *
29
     * @param \Closure $func
30
     * @param \Iterator $iterable
31
     */
32 22
    public function __construct(\Closure $func, \Iterator $iterable)
33
    {
34 22
        parent::__construct($iterable);
35 22
        $this->func = $func;
36 22
    }
37
38
    /**
39
     * @{inheritDoc}
40
     */
41 20
    public function key()
42
    {
43 20
        return call_user_func($this->func, $this->current(), parent::key());
44
    }
45
}
46