Last::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 1
eloc 4
c 3
b 1
f 0
nc 1
nop 0
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 1
rs 10
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