MapKeyStream   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 32
ccs 7
cts 7
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A key() 0 6 1
1
<?php
2
3
namespace Bdf\Collection\Stream;
4
5
use IteratorIterator;
6
7
/**
8
 * Implementation of StreamInterface::mapKey() return value
9
 *
10
 * @internal
11
 */
12
final class MapKeyStream extends IteratorIterator implements StreamInterface
13
{
14
    use StreamTrait;
15
16
    /**
17
     * @var callable
18
     */
19
    private $transformer;
20
21
22
    /**
23
     * MapStream constructor.
24
     *
25
     * @param StreamInterface $stream
26
     * @param callable $transformer
27
     */
28 27
    public function __construct(StreamInterface $stream, callable $transformer)
29
    {
30 27
        parent::__construct($stream);
31
32 27
        $this->transformer = $transformer;
33 27
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    #[\ReturnTypeWillChange]
39 25
    public function key()
40
    {
41 25
        $key = parent::key();
42
43 25
        return ($this->transformer)($this->current(), $key);
44
    }
45
}
46