MapKeyStream::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
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