Config   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 4 2
A has() 0 4 1
A set() 0 6 1
1
<?php
2
3
namespace PeterColes\Cluster;
4
5
class Config
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $configs = [];
11
12
    /**
13
     * Initialise configs.
14
     *
15
     * @param array $configs
16
     */
17
    public function __construct(array $configs = [])
18
    {
19
        $this->configs = $configs;
20
    }
21
22
    /**
23
     * Get a setting.
24
     *
25
     * @param string $key
26
     * @param mixed  $default
27
     *
28
     * @return mixed config setting or default when not found
29
     */
30
    public function get($key, $default = null)
31
    {
32
        return array_key_exists($key, $this->configs) ? $this->configs[$key] : $default;
33
    }
34
35
    /**
36
     * Check existence of an item by key.
37
     *
38
     * @param string $key
39
     * @return bool
40
     */
41
    public function has($key)
42
    {
43
        return array_key_exists($key, $this->configs);
44
    }
45
46
    /**
47
     * Set a setting.
48
     *
49
     * @param string $key
50
     * @param mixed  $value
51
     * @return $this
52
     */
53
    public function set($key, $value)
54
    {
55
        $this->configs[$key] = $value;
56
57
        return $this;
58
    }
59
}
60