BlockquoteConverter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 41
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedTags() 0 3 1
A convert() 0 23 3
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