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

EmphasisConverter::convert()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 8.8571
cc 5
eloc 10
nc 8
nop 1
crap 5
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