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

BlockquoteConverter::matches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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