Completed
Push — master ( 5c74fa...a4f811 )
by Arnold
02:37
created

iterable_has_any()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 2
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny;
6
7
/**
8
 * Check if any element matches the condition.
9
 *
10
 * @param iterable $iterable
11
 * @param callable $matcher
12
 * @return bool
13
 */
14
function iterable_has_any(iterable $iterable, callable $matcher): bool
15
{
16 18
    foreach ($iterable as $key => $value) {
17 17
        if ((bool)call_user_func($matcher, $value, $key)) {
18 17
            return true;
19
        }
20
    }
21
22 7
    return false;
23
}
24