| Conditions | 4 |
| Paths | 1 |
| Total Lines | 39 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | 5 | public function __invoke(): Closure |
|
| 22 | { |
||
| 23 | 5 | $reduceCallback = |
|
| 24 | /** |
||
| 25 | * @param array<int, array{0: int, 1: T}> $storage |
||
| 26 | * @param T $value |
||
| 27 | * |
||
| 28 | * @return array<int, array{0: int, 1: T}> |
||
| 29 | */ |
||
| 30 | 5 | static function (array $storage, $value): array { |
|
| 31 | 5 | $added = false; |
|
| 32 | |||
| 33 | 5 | foreach ($storage as $key => $data) { |
|
| 34 | 5 | if ($data[1] !== $value) { |
|
| 35 | 4 | continue; |
|
| 36 | } |
||
| 37 | |||
| 38 | 4 | ++$storage[$key][0]; |
|
| 39 | 4 | $added = true; |
|
| 40 | |||
| 41 | 4 | break; |
|
| 42 | } |
||
| 43 | |||
| 44 | 5 | if (true !== $added) { |
|
| 45 | 5 | $storage[] = [1, $value]; |
|
| 46 | } |
||
| 47 | |||
| 48 | 5 | return $storage; |
|
| 49 | 5 | }; |
|
| 50 | |||
| 51 | /** @var Closure(iterable<TKey, T>): Generator<int, T> $pipe */ |
||
| 52 | 5 | $pipe = (new Pipe())()( |
|
| 53 | 5 | (new Reduce())()($reduceCallback)([]), |
|
| 54 | 5 | (new Flatten())()(1), |
|
| 55 | 5 | (new Unpack())() |
|
| 56 | 5 | ); |
|
| 57 | |||
| 58 | // Point free style. |
||
| 59 | 5 | return $pipe; |
|
| 60 | } |
||
| 62 |