LoopHelper::pairwise()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 10
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Smoren\FormulaTools\Helpers;
4
5
class LoopHelper
6
{
7
    /**
8
     * @template T
9
     * @param array<T> $input
10
     * @return \Generator<array{T, T}>
11
     */
12 149
    public static function pairwise(array $input): \Generator
13
    {
14 149
        foreach ($input as $currentValue) {
15 148
            if (!isset($prevValue)) {
16 148
                $prevValue = $currentValue;
17 148
                continue;
18
            }
19
20 145
            yield [$prevValue, $currentValue];
21
22 121
            $prevValue = $currentValue;
23
        }
24
    }
25
}
26