Util   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A prepareOptions() 0 7 3
1
<?php
2
/**
3
 * This file is part of the Divergence package.
4
 *
5
 * (c) Henry Paradiz <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Divergence\Helpers;
12
13
/**
14
 * Util
15
 *
16
 * @package Divergence
17
 * @author Henry Paradiz <[email protected]>
18
 */
19
class Util
20
{
21
    /**
22
     * Prepares options.
23
     *
24
     * @param string|array $value Option. If provided a string will be assumed to be json and it will attempt to json_decode it and merge it with defaults. Or provide the array yourself.
25
     * @param array $defaults Defaults for the options array
26
     * @return array Merged array from $defaults and $value
27
     */
28 95
    public static function prepareOptions($value, $defaults = [])
29
    {
30 95
        if (is_string($value)) {
31 1
            $value = json_decode($value, true);
32
        }
33
34 95
        return is_array($value) ? array_merge($defaults, $value) : $defaults;
35
    }
36
}
37