IframeConverter::matches()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Sioen\HtmlToJson;
4
5
use Sioen\SirTrevorBlock;
6
7
final class IframeConverter implements Converter
8
{
9
    use HtmlToMarkdown;
10
11
    public function toJson(\DOMElement $node)
12
    {
13
        $html = $node->ownerDocument->saveXML($node);
14
15
        // youtube or vimeo
16 View Code Duplication
        if (preg_match('~//www.youtube.com/embed/([^/\?]+).*\"~si', $html, $matches)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
17
            return new SirTrevorBlock(
18
                'video',
19
                array(
20
                    'source' => 'youtube',
21
                    'remote_id' => $matches[1],
22
                )
23
            );
24
        }
25
26 View Code Duplication
        if (preg_match('~//player.vimeo.com/video/([^/\?]+).*\?~si', $html, $matches)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
27
            return new SirTrevorBlock(
28
                'video',
29
                array(
30
                    'source' => 'vimeo',
31
                    'remote_id' => $matches[1],
32
                )
33
            );
34
        }
35
    }
36
37
    public function matches(\DomElement $node)
38
    {
39
        return $node->nodeName === 'iframe';
40
    }
41
}
42