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

Filter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A of() 0 6 3
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