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

Configuration::checkForDeprecatedOptions()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 9
cts 9
cp 1
rs 9.2222
c 0
b 0
f 0
cc 6
nc 4
nop 1
crap 6
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 Colin O'Dell
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 Colin O'Dell
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