Utils   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 18
c 1
b 0
f 0
dl 0
loc 31
ccs 19
cts 19
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractField() 0 8 4
B EnsureArray() 0 18 8
1
<?php
2
3
namespace Gurucomkz\EagerLoading;
4
5
class Utils
6
{
7
8 8
    public static function EnsureArray($arr, $kfield = null)
9
    {
10 8
        if (is_array($arr)) {
11 1
            return $arr;
12
        }
13 7
        $result = [];
14 7
        foreach ($arr as $k => $v) {
15 7
            $key = $k;
16 7
            if ($kfield !== null) {
17 7
                if (is_array($v) && isset($v[$kfield])) {
18 6
                    $key = $v[$kfield];
19 1
                } elseif (is_object($v) && property_exists($v, $kfield)) {
20 1
                    $key = $v->$kfield;
21
                }
22
            }
23 7
            $result[$key] = $v;
24
        }
25 7
        return $result;
26
    }
27
28 6
    public static function extractField($arr, $field)
29
    {
30 6
        $result = [];
31 6
        foreach ($arr as $record) {
32 6
            $key = is_object($record) ? $record->ID : $record['ID'];
33 6
            $result[$key] = is_object($record) ? $record->$field : $record[$field];
34
        }
35 6
        return $result;
36
    }
37
}
38