IframeConverter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 51.43 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B toJson() 18 25 3
A matches() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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