iterable_after()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 6
nc 5
nop 3
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Improved;
6
7
/**
8
 * Get elements after a match is found.
9
 *
10
 * @param iterable $iterable
11
 * @param callable $matcher
12
 * @param bool     $including
13
 * @return \Generator
14
 */
15 17
function iterable_after(iterable $iterable, callable $matcher, bool $including = false): \Generator
0 ignored issues
show
introduced by
Function Improved\iterable_after() has parameter $iterable with no value type specified in iterable type iterable.
Loading history...
introduced by
Function Improved\iterable_after() return type has no value type specified in iterable type Generator.
Loading history...
16
{
17 16
    $found = false;
18
19 16
    foreach ($iterable as $key => $value) {
20 15
        $matched = $found || (bool)call_user_func($matcher, $value, $key);
21
22 15
        if ($found || ($matched && $including)) {
23 15
            yield $key => $value;
24
        }
25
26 15
        $found = $matched;
27
    }
28
}
29