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

Helper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 15
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 15
ccs 9
cts 9
cp 1
rs 10

1 Method

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