Completed
Pull Request — master (#118)
by Filip
24:11 queued 22:16
created

Configuration::merge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace League\HTMLToMarkdown;
4
5
class Configuration
6
{
7
    protected $config;
8
9
    /**
10
     * @param array $config
11
     */
12 87
    public function __construct(array $config = array())
13
    {
14 87
        $this->config = $config;
15 87
    }
16
17
    /**
18
     * @param array $config
19
     */
20 81
    public function merge(array $config = array())
21
    {
22 81
        $this->config = array_replace_recursive($this->config, $config);
23 81
    }
24
25
    /**
26
     * @param array $config
27
     */
28
    public function replace(array $config = array())
29
    {
30
        $this->config = $config;
31
    }
32
33
    /**
34
     * @param string $key
35
     * @param mixed  $value
36
     */
37 6
    public function setOption($key, $value)
38
    {
39 6
        $this->config[$key] = $value;
40 6
    }
41
42
    /**
43
     * @param string|null $key
44
     * @param mixed|null  $default
45
     *
46
     * @return mixed|null
47
     */
48 78
    public function getOption($key = null, $default = null)
49
    {
50 78
        if ($key === null) {
51
            return $this->config;
52
        }
53
54 78
        if (!isset($this->config[$key])) {
55 3
            return $default;
56
        }
57
58 75
        return $this->config[$key];
59
    }
60
}
61