Arr::unwrap()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 2
crap 3
1
<?php
2
3
namespace Mosaic\Common;
4
5
class Arr
6
{
7
    /**
8
     * @param mixed       $input
9
     * @param mixed       $key
10
     * @param string|null $default
11
     *
12
     * @return mixed
13
     */
14 2
    public static function get($input, $key, $default = null)
15
    {
16 2
        if (array_key_exists($key, $input)) {
17 1
            return $input[$key];
18
        }
19
20 1
        return $default;
21
    }
22
23
    /**
24
     * Unwraps a single item array into the item. If the array contains more than one item, it will be returned as-is.
25
     * A default value can be provided, and will be used when an empty array is given.
26
     *
27
     * @param array      $input
28
     * @param mixed|null $default
29
     *
30
     * @return mixed
31
     */
32 3
    public static function unwrap(array $input, $default = null)
33
    {
34 3
        if (count($input) > 1) {
35 1
            return $input;
36
        }
37
38 2
        return ! empty($input) ? current($input) : $default;
39
    }
40
}
41