BlockquoteConverter::convert()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 23
ccs 11
cts 11
cp 1
crap 3
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Pilipinews\Common\Converters;
4
5
use League\HTMLToMarkdown\Converter\ConverterInterface;
6
use League\HTMLToMarkdown\ElementInterface;
7
8
/**
9
 * Blockquote Converter
10
 *
11
 * @package Pilipinews
12
 * @author  Rougin Gutib <[email protected]>
13
 */
14
class BlockquoteConverter implements ConverterInterface
15
{
16
    /**
17
     * Converts the specified element into a parsed string.
18
     *
19
     * @param  \League\HTMLToMarkdown\ElementInterface $element
20
     * @return string
21
     */
22 3
    public function convert(ElementInterface $element)
23
    {
24
        // Contents should have already been converted to Markdown by this point,
25
        // so we just need to add '>' symbols to each line.
26
27 3
        $markdown = '';
28
29 3
        $quote = trim($element->getValue());
30
31 3
        $lines = preg_split('/\r\n|\r|\n/', $quote);
32
33 3
        $total = count((array) $lines);
34
35 3
        foreach ($lines as $i => $line)
36
        {
37 3
            $markdown .= '> ' . $line . "\n";
38
39 3
            $newline = $i + 1 === $total;
40
41 3
            $newline && $markdown .= "\n";
42 1
        }
43
44 3
        return "\n\n" . $markdown;
45
    }
46
47
    /**
48
     * Returns the supported HTML tags.
49
     *
50
     * @return string[]
51
     */
52 15
    public function getSupportedTags()
53
    {
54 15
        return array('blockquote');
55
    }
56
}
57