Completed
Push — master ( 5ca5da...4b9539 )
by Colin
13s queued 10s
created

HardBreakConverter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 48
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setConfig() 0 4 1
B convert() 0 19 7
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 HardBreakConverter implements ConverterInterface, ConfigurationAwareInterface
10
{
11
    /**
12
     * @var Configuration
13
     */
14
    protected $config;
15
16
    /**
17
     * @param Configuration $config
18
     */
19 84
    public function setConfig(Configuration $config)
20
    {
21 84
        $this->config = $config;
22 84
    }
23
24
    /**
25
     * @param ElementInterface $element
26
     *
27
     * @return string
28
     */
29 9
    public function convert(ElementInterface $element)
30
    {
31 9
        $return = $this->config->getOption('hard_break') ? "\n" : "  \n";
32
33 9
        $next = $element->getNext();
34 9
        if ($next) {
35 9
            $next_value = $next->getValue();
36 9
            if ($next_value) {
37 9
                if (in_array(substr($next_value, 0, 2), array('- ', '* ', '+ '))) {
38 3
                    $parent = $element->getParent();
39 3
                    if ($parent && $parent->getTagName() == 'li') {
40 3
                        $return .= '\\';
41 2
                    }
42 2
                }
43 6
            }
44 6
        }
45
46 9
        return $return;
47
    }
48
49
    /**
50
     * @return string[]
51
     */
52 84
    public function getSupportedTags()
53
    {
54 84
        return array('br');
55
    }
56
}
57