Completed
Pull Request — master (#83)
by
unknown
23:04
created

EmphasisConverter::setConfig()   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
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace League\HTMLToMarkdown\Converter;
4
5
use League\HTMLToMarkdown\Configuration;
6
use League\HTMLToMarkdown\ConfigurationAwareInterface;
7
use League\HTMLToMarkdown\ElementInterface;
8
9
class EmphasisConverter implements ConverterInterface, ConfigurationAwareInterface
10
{
11
    /**
12
     * @var Configuration
13
     */
14
    protected $config;
15
16
    /**
17
     * @param Configuration $config
18
     */
19 66
    public function setConfig(Configuration $config)
20
    {
21 66
        $this->config = $config;
22 66
    }
23
24
    /**
25
     * @param ElementInterface $element
26
     *
27
     * @return string
28
     */
29 6
    public function convert(ElementInterface $element)
30
    {
31 6
        $tag = $element->getTagName();
32 6
        $value = $element->getValue();
33
34 6
        if ($tag === 'i' || $tag === 'em') {
35 6
            $style = $this->config->getOption('italic_style');
36 6
        } else {
37 6
            $style = $this->config->getOption('bold_style');
38
        }
39
40 6
        $prefix = ltrim($value) !== $value ? ' ' : '';
41
        $suffix = rtrim($value) !== $value ? ' ' : '';
42
43
        return $prefix . $style . trim($value) . $style . $suffix;
44
    }
45
46 66
    /**
47
     * @return string[]
48 66
     */
49
    public function getSupportedTags()
50
    {
51
        return array('em', 'i', 'strong', 'b');
52
    }
53
}
54