Completed
Push — master ( e6fd7b...87ba8f )
by Colin
02:12
created

Configuration::setOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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
16 87
        $this->checkForDeprecatedOptions($config);
17 87
    }
18
19
    /**
20
     * @param array $config
21
     */
22 81
    public function merge(array $config = array())
23
    {
24 81
        $this->checkForDeprecatedOptions($config);
25 81
        $this->config = array_replace_recursive($this->config, $config);
26 81
    }
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 81
    public function getOption($key = null, $default = null)
54
    {
55 81
        if ($key === null) {
56
            return $this->config;
57
        }
58
59 81
        if (!isset($this->config[$key])) {
60 12
            return $default;
61
        }
62
63 78
        return $this->config[$key];
64
    }
65
66 87
    private function checkForDeprecatedOptions(array $config)
67
    {
68 87
        foreach ($config as $key => $value) {
69 81
            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 81
            } elseif ($key === 'italic_style' && $value !== '*') {
72 29
                @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 2
            }
74 58
        }
75 87
    }
76
}
77