Passed
Pull Request — master (#31)
by Josh
04:13
created

AbstractTableElement   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 8
c 3
b 0
f 0
lcom 1
cbo 0
dl 7
loc 49
ccs 0
cts 23
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDomNode() 0 4 1
A setDomNode() 0 6 1
A getInnerHtml() 0 12 3
A getAttribute() 0 3 1
A htmlFromNode() 7 7 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 Caxy\HtmlDiff\Table;
4
5
abstract class AbstractTableElement
6
{
7
    /**
8
     * @var \DOMElement
9
     */
10
    protected $domNode;
11
12
    public function __construct(\DOMElement $domNode = null)
13
    {
14
        $this->domNode = $domNode;
15
    }
16
17
    public function getDomNode()
18
    {
19
        return $this->domNode;
20
    }
21
22
    public function setDomNode(\DOMElement $domNode)
23
    {
24
        $this->domNode = $domNode;
25
26
        return $this;
27
    }
28
29
    public function getInnerHtml()
30
    {
31
        $innerHtml = '';
32
33
        if ($this->domNode) {
34
            foreach ($this->domNode->childNodes as $child) {
35
                $innerHtml .= static::htmlFromNode($child);
36
            }
37
        }
38
39
        return $innerHtml;
40
    }
41
42
    public function getAttribute($name) {
43
        return $this->domNode->getAttribute($name);
44
    }
45
46 View Code Duplication
    public static function htmlFromNode($node)
0 ignored issues
show
Duplication introduced by
This method 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...
47
    {
48
        $domDocument = new \DOMDocument();
49
        $newNode = $domDocument->importNode($node, true);
50
        $domDocument->appendChild($newNode);
51
        return trim($domDocument->saveHTML());
52
    }
53
}
54