Passed
Push — 5.x ( 65a76f...3a1e20 )
by Enjoys
59s queued 13s
created

Helper::arrayRecursiveSearchKeyMap()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.6111
cc 5
nc 5
nop 2
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enjoys\Forms;
6
7
final class Helper
8
{
9 29
    public static function arrayRecursiveSearchKeyMap(mixed $needle, array $haystack): array|null
10
    {
11 29
        foreach ($haystack as $firsLevelKey => $value) {
12 29
            if ($needle === $value) {
13 18
                return array($firsLevelKey);
14 28
            } elseif (is_array($value)) {
15 28
                $callback = self::arrayRecursiveSearchKeyMap($needle, $value);
16 28
                if ($callback) {
17 15
                    return array_merge(array($firsLevelKey), $callback);
18
                }
19
            }
20
        }
21 23
        return null;
22
    }
23
}
24