Passed
Push — master ( e3dd73...0b1820 )
by Pol
01:36
created

Current::of()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\fpt;
6
7
use Closure;
8
9
// phpcs:disable Generic.Files.LineLength.TooLong
10
11
/**
12
 * @psalm-immutable
13
 *
14
 * @psalm-template T
15
 */
16
final class Current
17
{
18
    /**
19
     * @psalm-pure
20
     */
21 1
    public static function of(): Closure
22
    {
23
        return
24
            /**
25
             * @psalm-param iterable<T> $iterable
26
             * @psalm-return ?T
27
             */
28 1
            static function (iterable $iterable) {
29 1
                $current = null;
30
31 1
                foreach ($iterable as $current) {
32 1
                    break;
33
                }
34
35 1
                return $current;
36 1
            };
37
    }
38
}
39