Completed
Push — master ( bd601b...3b64e5 )
by Colin
8s
created

EmphasisConverter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.12%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 8
c 3
b 2
f 0
lcom 1
cbo 2
dl 0
loc 49
ccs 16
cts 17
cp 0.9412
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setConfig() 0 4 1
B convert() 0 20 6
A getSupportedTags() 0 4 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 75
    public function setConfig(Configuration $config)
20
    {
21 75
        $this->config = $config;
22 75
    }
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 (!trim($value)) {
35
            return '';
36
        }
37
38 6
        if ($tag === 'i' || $tag === 'em') {
39 6
            $style = $this->config->getOption('italic_style');
40 6
        } else {
41 6
            $style = $this->config->getOption('bold_style');
42
        }
43
44 6
        $prefix = ltrim($value) !== $value ? ' ' : '';
45 6
        $suffix = rtrim($value) !== $value ? ' ' : '';
46
47 6
        return $prefix . $style . trim($value) . $style . $suffix;
48
    }
49
50
    /**
51
     * @return string[]
52
     */
53 75
    public function getSupportedTags()
54
    {
55 75
        return array('em', 'i', 'strong', 'b');
56
    }
57
}
58