DefaultConverter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 37
ccs 11
cts 11
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convert() 0 17 3
A setConfig() 0 3 1
A getSupportedTags() 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 DefaultConverter implements ConverterInterface, ConfigurationAwareInterface
12
{
13
    public const DEFAULT_CONVERTER = '_default';
14
15
    /** @var Configuration */
16
    protected $config;
17
18
    public function setConfig(Configuration $config): void
19
    {
20
        $this->config = $config;
21 102
    }
22
23 102
    public function convert(ElementInterface $element): string
24 102
    {
25
        // If strip_tags is false (the default), preserve tags that don't have Markdown equivalents,
26
        // such as <span> nodes on their own. C14N() canonicalizes the node to a string.
27
        // See: http://www.php.net/manual/en/domnode.c14n.php
28
        if ($this->config->getOption('strip_tags', false)) {
29
            return $element->getValue();
30
        }
31 96
32
        $markdown = \html_entity_decode($element->getChildrenAsString());
33
34
        // Tables are only handled here if TableConverter is not used
35
        if ($element->getTagName() === 'table') {
36 96
            $markdown .= "\n\n";
37 18
        }
38
39
        return $markdown;
40 87
    }
41
42
    /**
43 87
     * @return string[]
44 3
     */
45 2
    public function getSupportedTags(): array
46
    {
47 87
        return [self::DEFAULT_CONVERTER];
48
    }
49
}
50