Arr   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 36
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A unwrap() 0 8 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