MappedTraversable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 24
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIterator() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BenTools\IterableFunctions;
6
7
use IteratorAggregate;
8
use Traversable;
9
10
/**
11
 * @internal
12
 *
13
 * @implements IteratorAggregate<mixed>
14
 */
15
final class MappedTraversable implements IteratorAggregate
16
{
17
    /** @var Traversable<mixed> */
18
    private $traversable;
19
20
    /** @var callable */
21
    private $mapper;
22
23
    /**
24
     * @param Traversable<mixed> $traversable
25
     */
26
    public function __construct(Traversable $traversable, callable $mapper)
27
    {
28
        $this->traversable = $traversable;
29
        $this->mapper = $mapper;
30
    }
31
32
    /**
33
     * @return Traversable<mixed>
34
     */
35
    public function getIterator(): Traversable
36
    {
37
        foreach ($this->traversable as $key => $value) {
38
            yield $key => ($this->mapper)($value);
39
        }
40
    }
41
}
42