Completed
Push — master ( a2b906...d5b295 )
by Peter
03:27
created

Config::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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