ProviderGetValue   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 11 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Eclipxe\XlsxExporter\Utils;
6
7
use ArrayAccess;
8
9
class ProviderGetValue
10
{
11
    /**
12
     * Retrieve a value from a key-value array, an ArrayAccess object or an object property
13
     *
14
     * @param mixed $values
15
     * @return scalar|null
16
     */
17 17
    public static function get($values, string $key)
18
    {
19 17
        $asObject = is_object($values);
20 17
        $asArray = is_array($values) || $values instanceof ArrayAccess;
21 17
        if ($asArray) {
22 13
            return $values[$key] ?? null;
23
        }
24 5
        if ($asObject) {
25 3
            return $values->{$key} ?? null;
26
        }
27 2
        return null;
28
    }
29
}
30