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

HeadingConverter::toJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Sioen\HtmlToJson;
4
5 View Code Duplication
class HeadingConverter extends Converter
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6
{
7 1
    public function toJson(\DOMElement $node)
8
    {
9 1
        $html = $node->ownerDocument->saveXML($node);
10
11
        // remove the h2 tags from the text. We just need the inner text.
12 1
        $html = preg_replace('/<(\/|)h2>/i', '', $html);
13
14
        return array(
15 1
            'type' => 'heading',
16
            'data' => array(
17 1
                'text' => ' ' . $this->htmlToMarkdown($html)
18 1
            )
19 1
        );
20
    }
21
22 1
    public function matches(\DomElement $node)
23
    {
24 1
        return $node->nodeName === 'h2';
25 1
    }
26
}
27