ProviderGetValue::get()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 6
nop 2
dl 0
loc 11
ccs 8
cts 8
cp 1
crap 4
rs 10
c 0
b 0
f 0
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