BlockquoteConverter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 5
c 4
b 0
f 1
lcom 1
cbo 2
dl 0
loc 50
rs 10
ccs 26
cts 26
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toJson() 0 16 1
A matches() 0 4 1
A getCiteHtml() 0 13 2
A getCiteNodes() 0 9 1
1
<?php
2
3
namespace Sioen\HtmlToJson;
4
5
use Sioen\SirTrevorBlock;
6
7
final class BlockquoteConverter implements Converter
8
{
9
    use HtmlToMarkdown;
10
11 1
    public function toJson(\DOMElement $node)
12
    {
13 1
        $cite = $this->getCiteHtml($node);
14
15
        // we use the remaining html to create the remaining text
16 1
        $html = $node->ownerDocument->saveXML($node);
17 1
        $html = preg_replace('/<(\/|)blockquote>/i', '', $html);
18
19 1
        return new SirTrevorBlock(
20 1
            'quote',
21
            array(
22 1
                'text' => ' ' . $this->htmlToMarkdown($html),
23 1
                'cite' => $cite,
24
            )
25 1
        );
26
    }
27
28 1
    public function matches(\DomElement $node)
29
    {
30 1
        return $node->nodeName === 'blockquote';
31
    }
32
33 1
    private function getCiteHtml(\DOMElement $node)
34
    {
35 1
        $cite = '';
36
37 1
        foreach ($this->getCiteNodes($node) as $child) {
38 1
            $html = $child->ownerDocument->saveXML($child);
39 1
            $html = preg_replace('/<(\/|)cite>/i', '', $html);
40 1
            $child->parentNode->removeChild($child);
41 1
            $cite = ' ' . $this->htmlToMarkdown($html);
42 1
        }
43
44 1
        return $cite;
45
    }
46
47 1
    private function getCiteNodes(\DOMElement $node)
48
    {
49 1
        return array_filter(
50 1
            iterator_to_array($node->childNodes),
51 1
            function (\DOMElement $childNode) {
52 1
                return $childNode->nodeName == 'cite';
53
            }
54 1
        );
55
    }
56
}
57