Helper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 9
c 1
b 0
f 1
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A arrayRecursiveSearchKeyMap() 0 14 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