ListConverter::toJson()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 12
loc 12
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace Sioen\HtmlToJson;
4
5
use Sioen\SirTrevorBlock;
6
7 View Code Duplication
final class ListConverter implements 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...
8
{
9
    use HtmlToMarkdown;
10
11
    public function toJson(\DOMElement $node)
12
    {
13
        $markdown = $this->htmlToMarkdown($node->ownerDocument->saveXML($node));
14
15
        // we need a space in the beginning of each line
16
        $markdown = ' ' . str_replace("\n", "\n ", $markdown);
17
18
        return new SirTrevorBlock(
19
            'list',
20
            array('text' => $markdown)
21
        );
22
    }
23
24
    public function matches(\DomElement $node)
25
    {
26
        return $node->nodeName === 'ul';
27
    }
28
}
29