Configuration::has()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Stevenmaguire\Services\Trello;
4
5
class Configuration
6
{
7
    /**
8
     * Settings
9
     *
10
     * @var array
11
     */
12
    protected static $settings = [];
13
14
    /**
15
     * Confirms that a given key exists in configuration settings.
16
     *
17
     * @param  string $key
18
     *
19 8
     * @return bool
20
     */
21 8
    public static function has($key)
22
    {
23
        return isset(static::$settings[$key]);
24
    }
25
26
    /**
27
     * Attempts to retrieve a given key from configuration settings. Returns
28
     * default if not set.
29
     *
30
     * @param  string $key
31
     * @param  mixed  $default
32
     *
33 708
     * @return mixed
34
     */
35 708
    public static function get($key = null, $default = null)
36 706
    {
37
        if (! empty($key)) {
38
            return isset(static::$settings[$key]) ? static::$settings[$key] : $default;
39 2
        }
40
41
        return static::$settings;
42
    }
43
44
    /**
45
     * Parses give options against default options.
46
     *
47
     * @param  array   $options
48
     * @param  array   $defaults
49
     *
50 712
     * @return array
51
     */
52
    public static function parseDefaultOptions($options = [], $defaults = [])
53 702
    {
54 702
        array_walk($defaults, function ($value, $key) use (&$options) {
55 351
            if (! isset($options[$key])) {
56 712
                $options[$key] = $value;
57
            }
58 712
        });
59
60
        return $options;
61
    }
62
63
    /**
64
     * Updates configuration settings with key value pair.
65
     *
66
     * @param string $key
67
     * @param mixed  $value
68
     *
69 712
     * @return void
70
     */
71 712
    public static function set($key, $value)
72 712
    {
73
        static::$settings[$key] = $value;
74
    }
75
76
    /**
77
     * Updates configuration settings with collection of key value pairs.
78
     *
79
     * @param array $settings
80
     *
81 712
     * @return void
82
     */
83 712
    public static function setMany($settings = [], $defaultSettings = [])
84
    {
85 712
        $settings = static::parseDefaultOptions($settings, $defaultSettings);
86 712
87 712
        array_walk($settings, function ($value, $key) {
88 712
            static::set($key, $value);
89
        });
90 2
    }
91
}
92