CommentConverter::getSupportedTags()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
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 CommentConverter 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
        if ($this->shouldPreserve($element)) {
24
            return '<!--' . $element->getValue() . '-->';
25
        }
26
27
        return '';
28
    }
29 6
30
    /**
31 6
     * @return string[]
32 3
     */
33
    public function getSupportedTags(): array
34 6
    {
35
        return ['#comment'];
36
    }
37
38
    private function shouldPreserve(ElementInterface $element): bool
39
    {
40 99
        $preserve = $this->config->getOption('preserve_comments');
41
        if ($preserve === true) {
42 99
            return true;
43
        }
44
45
        if (\is_array($preserve)) {
46
            $value = \trim($element->getValue());
47
48
            return \in_array($value, $preserve, true);
49
        }
50 6
51
        return false;
52 6
    }
53
}
54