Helper::arrayRecursiveSearchKeyMap()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
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 14
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
        /** @psalm-suppress MixedAssignment */
12 29
        foreach ($haystack as $firsLevelKey => $value) {
13 29
            if ($needle === $value) {
14 18
                return array($firsLevelKey);
15 28
            } elseif (is_array($value)) {
16 28
                $callback = self::arrayRecursiveSearchKeyMap($needle, $value);
17 28
                if ($callback) {
18 15
                    return array_merge(array($firsLevelKey), $callback);
19
                }
20
            }
21
        }
22 23
        return null;
23
    }
24
}
25