Last   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 5
c 3
b 1
f 0
dl 0
loc 16
ccs 6
cts 6
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\collection\Operation;
6
7
use Closure;
8
use Generator;
9
10
/**
11
 * @immutable
12
 *
13
 * @template TKey
14
 * @template T
15
 */
16
final class Last extends AbstractOperation
17
{
18
    /**
19
     * @return Closure(iterable<TKey, T>): Generator<TKey, T>
20
     */
21 46
    public function __invoke(): Closure
22
    {
23
        /** @var Closure(iterable<TKey, T>): Generator<TKey, T> $pipe */
24 46
        $pipe = (new Pipe())()(
25 46
            (new Reverse())(),
26
            // We could use `Head` here, but I use `Limit` for minor perf boost.
27 46
            (new Limit())()(1)(0)
28 46
        );
29
30
        // Point free style.
31 46
        return $pipe;
32
    }
33
}
34