Implode   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 18 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\collection\Operation;
6
7
use Closure;
8
use Generator;
9
use Stringable;
10
11
/**
12
 * @immutable
13
 *
14
 * @template TKey
15
 * @template T
16
 */
17
final class Implode extends AbstractOperation
18
{
19
    /**
20
     * @return Closure(string): Closure(iterable<TKey, T>): Generator<TKey, string>
21
     */
22 10
    public function __invoke(): Closure
23
    {
24 10
        return
25
            /**
26
             * @return Closure(iterable<TKey, T>): Generator<TKey, string>
27
             */
28 10
            static function (string $glue): Closure {
29
                /** @var Closure(iterable<TKey, T>): Generator<TKey, string> $pipe */
30 10
                $pipe = (new Pipe())()(
31 10
                    (new Intersperse())()($glue)(1)(0),
32 10
                    (new Limit())()(-1)(1),
33 10
                    (new Reduce())()(
34 10
                        static fn (string $carry, string|Stringable $item): string => $carry .= (string) $item
35 10
                    )('')
36 10
                );
37
38
                // Point free style.
39 10
                return $pipe;
40 10
            };
41
    }
42
}
43