Completed
Push — SOLID ( ba508c...d6070b )
by Wouter
01:49
created

BlockquoteConverter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 35
ccs 18
cts 18
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B toJson() 0 27 3
A matches() 0 4 1
1
<?php
2
3
namespace Sioen\HtmlToJson;
4
5
class BlockquoteConverter extends Converter
6
{
7 1
    public function toJson(\DOMElement $node)
8
    {
9
        // check if the quote contains a cite
10 1
        $cite = '';
11
12 1
        foreach ($node->childNodes as $child) {
13
            // if it contains a 'cite' node, we should add it in the cite property
14 1
            if ($child->nodeName == 'cite') {
15 1
                $html = $child->ownerDocument->saveXML($child);
16 1
                $html = preg_replace('/<(\/|)cite>/i', '', $html);
17 1
                $child->parentNode->removeChild($child);
18 1
                $cite = ' ' . $this->htmlToMarkdown($html);
19 1
            }
20 1
        }
21
22
        // we use the remaining html to create the remaining text
23 1
        $html = $node->ownerDocument->saveXML($node);
24 1
        $html = preg_replace('/<(\/|)blockquote>/i', '', $html);
25
26
        return array(
27 1
            'type' => 'quote',
28
            'data' => array(
29 1
                'text' => ' ' . $this->htmlToMarkdown($html),
30
                'cite' => $cite
31 1
            )
32 1
        );
33
    }
34
35 1
    public function matches(\DomElement $node)
36
    {
37 1
        return $node->nodeName === 'blockquote';
38
    }
39
}
40