BlockquoteConverter::convert()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 10
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 22
ccs 11
cts 11
cp 1
crap 3
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\HTMLToMarkdown\Converter;
6
7
use League\HTMLToMarkdown\ElementInterface;
8
9
class BlockquoteConverter implements ConverterInterface
10
{
11
    public function convert(ElementInterface $element): string
12
    {
13
        // Contents should have already been converted to Markdown by this point,
14 6
        // so we just need to add '>' symbols to each line.
15
16
        $markdown = '';
17
18
        $quoteContent = \trim($element->getValue());
19 6
20
        $lines = \preg_split('/\r\n|\r|\n/', $quoteContent);
21 6
        \assert(\is_array($lines));
22
23 6
        $totalLines = \count($lines);
24
25 6
        foreach ($lines as $i => $line) {
26
            $markdown .= '> ' . $line . "\n";
27 6
            if ($i + 1 === $totalLines) {
28 6
                $markdown .= "\n";
29 6
            }
30 6
        }
31 4
32 4
        return $markdown;
33
    }
34 6
35
    /**
36
     * @return string[]
37
     */
38
    public function getSupportedTags(): array
39
    {
40 99
        return ['blockquote'];
41
    }
42
}
43