Config   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 97
ccs 19
cts 19
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 8 2
A has() 0 4 1
A getDefault() 0 8 2
A set() 0 6 1
A setFallback() 0 6 1
1
<?php
2
3
namespace League\Flysystem;
4
5
class Config
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $settings = array();
11
12
    /**
13
     * @var Config
14
     */
15
    protected $fallback;
16
17
    /**
18
     * Constructor.
19
     *
20
     * @param array $settings
21
     */
22 234
    public function __construct(array $settings = array())
23
    {
24 234
        $this->settings = $settings;
25 234
    }
26
27
    /**
28
     * Get a setting.
29
     *
30
     * @param string $key
31
     * @param mixed  $default
32
     *
33
     * @return mixed config setting or default when not found
34
     */
35 132
    public function get($key, $default = null)
36
    {
37 132
        if ( ! array_key_exists($key, $this->settings)) {
38 120
            return $this->getDefault($key, $default);
39
        }
40
41 18
        return $this->settings[$key];
42
    }
43
44
    /**
45
     * Check if an item exists by key.
46
     *
47
     * @param string $key
48
     *
49
     * @return bool
50
     */
51 3
    public function has($key)
52
    {
53 3
        return array_key_exists($key, $this->settings);
54
    }
55
56
    /**
57
     * Try to retrieve a default setting from a config fallback.
58
     *
59
     * @param string $key
60
     * @param mixed  $default
61
     *
62
     * @return mixed config setting or default when not found
63
     */
64 120
    protected function getDefault($key, $default)
65
    {
66 120
        if ( ! $this->fallback) {
67 120
            return $default;
68
        }
69
70 21
        return $this->fallback->get($key, $default);
71
    }
72
73
    /**
74
     * Set a setting.
75
     *
76
     * @param string $key
77
     * @param mixed  $value
78
     *
79
     * @return $this
80
     */
81 3
    public function set($key, $value)
82
    {
83 3
        $this->settings[$key] = $value;
84
85 3
        return $this;
86
    }
87
88
    /**
89
     * Set the fallback.
90
     *
91
     * @param Config $fallback
92
     *
93
     * @return $this
94
     */
95 57
    public function setFallback(Config $fallback)
96
    {
97 57
        $this->fallback = $fallback;
98
99 57
        return $this;
100
    }
101
}
102