Passed
Push — master ( 2236ae...d0b86a )
by Pol
11:24
created

Filter::of()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\fpt;
6
7
use Closure;
8
use Generator;
9
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
10
11
// phpcs:disable Generic.Files.LineLength.TooLong
12
13
/**
14
 * @psalm-immutable
15
 */
16
final class Filter
17
{
18
    /**
19
     * @psalm-pure
20
     */
21
    public static function of(): Closure
22
    {
23
        return static fn (callable $callable): Closure => static function (iterable $iterable) use ($callable): Generator {
24
            foreach ($iterable as $key => $value) {
25
                if ($callable($value)) {
26
                    yield $key => $value;
27
                }
28
            }
29
        };
30
    }
31
}
32