Completed
Push — master ( 0868ae...a5d47a )
by Colin
03:35
created

Configuration   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 82.76%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 0
dl 0
loc 72
ccs 24
cts 29
cp 0.8276
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A merge() 0 5 1
A replace() 0 5 1
A setOption() 0 5 1
A getOption() 0 12 3
A checkForDeprecatedOptions() 0 10 6
1
<?php
2
3
namespace League\HTMLToMarkdown;
4
5
class Configuration
6
{
7
    protected $config;
8
9
    /**
10
     * @param array $config
11
     */
12 96
    public function __construct(array $config = array())
13
    {
14 96
        $this->config = $config;
15
16 96
        $this->checkForDeprecatedOptions($config);
17 96
    }
18
19
    /**
20
     * @param array $config
21
     */
22 90
    public function merge(array $config = array())
23
    {
24 90
        $this->checkForDeprecatedOptions($config);
25 90
        $this->config = array_replace_recursive($this->config, $config);
26 90
    }
27
28
    /**
29
     * @param array $config
30
     */
31
    public function replace(array $config = array())
32
    {
33
        $this->checkForDeprecatedOptions($config);
34
        $this->config = $config;
35
    }
36
37
    /**
38
     * @param string $key
39
     * @param mixed  $value
40
     */
41 6
    public function setOption($key, $value)
42
    {
43 6
        $this->checkForDeprecatedOptions(array($key => $value));
44 6
        $this->config[$key] = $value;
45 6
    }
46
47
    /**
48
     * @param string|null $key
49
     * @param mixed|null  $default
50
     *
51
     * @return mixed|null
52
     */
53 90
    public function getOption($key = null, $default = null)
54
    {
55 90
        if ($key === null) {
56
            return $this->config;
57
        }
58
59 90
        if (!isset($this->config[$key])) {
60 15
            return $default;
61
        }
62
63 87
        return $this->config[$key];
64
    }
65
66 96
    private function checkForDeprecatedOptions(array $config)
67
    {
68 96
        foreach ($config as $key => $value) {
69 90
            if ($key === 'bold_style' && $value !== '**') {
70 3
                @trigger_error('Customizing the bold_style option is deprecated and may be removed in the next major version', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
71 90
            } elseif ($key === 'italic_style' && $value !== '*') {
72 3
                @trigger_error('Customizing the italic_style option is deprecated and may be removed in the next major version', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
73
            }
74
        }
75 96
    }
76
}
77