HardBreakConverter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 36
ccs 18
cts 18
cp 1
rs 10
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedTags() 0 3 1
B convert() 0 18 7
A setConfig() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\HTMLToMarkdown\Converter;
6
7
use League\HTMLToMarkdown\Configuration;
8
use League\HTMLToMarkdown\ConfigurationAwareInterface;
9
use League\HTMLToMarkdown\ElementInterface;
10
11
class HardBreakConverter implements ConverterInterface, ConfigurationAwareInterface
12
{
13
    /** @var Configuration */
14
    protected $config;
15
16
    public function setConfig(Configuration $config): void
17
    {
18
        $this->config = $config;
19 99
    }
20
21 99
    public function convert(ElementInterface $element): string
22 99
    {
23
        $return = $this->config->getOption('hard_break') ? "\n" : "  \n";
24
25
        $next = $element->getNext();
26
        if ($next) {
27
            $nextValue = $next->getValue();
28
            if ($nextValue) {
29 9
                if (\in_array(\substr($nextValue, 0, 2), ['- ', '* ', '+ '], true)) {
30
                    $parent = $element->getParent();
31 9
                    if ($parent && $parent->getTagName() === 'li') {
32
                        $return .= '\\';
33 9
                    }
34 9
                }
35 9
            }
36 9
        }
37 9
38 3
        return $return;
39 3
    }
40 3
41 2
    /**
42 2
     * @return string[]
43 6
     */
44 6
    public function getSupportedTags(): array
45
    {
46 9
        return ['br'];
47
    }
48
}
49