Passed
Pull Request — master (#62)
by
unknown
05:01
created

AbstractTableElement   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 87
Duplicated Lines 8.05 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 86.96%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 7
loc 87
ccs 20
cts 23
cp 0.8696
rs 10
c 2
b 0
f 0
wmc 9
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttribute() 0 4 1
A cloneNode() 0 4 1
A __construct() 0 4 1
A getDomNode() 0 4 1
A setDomNode() 0 6 1
A getInnerHtml() 0 12 3
A htmlFromNode() 7 8 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
/**
6
 * Class AbstractTableElement.
7
 */
8
abstract class AbstractTableElement
9
{
10
    /**
11
     * @var \DOMElement
12
     */
13
    protected $domNode;
14
15
    /**
16
     * AbstractTableElement constructor.
17
     *
18
     * @param \DOMElement|null $domNode
19
     */
20 1
    public function __construct(\DOMElement $domNode = null)
21
    {
22 1
        $this->domNode = $domNode;
23 1
    }
24
25
    /**
26
     * @return \DOMElement
27
     */
28 1
    public function getDomNode()
29
    {
30 1
        return $this->domNode;
31
    }
32
33
    /**
34
     * @param \DOMElement $domNode
35
     *
36
     * @return $this
37
     */
38
    public function setDomNode(\DOMElement $domNode)
39
    {
40
        $this->domNode = $domNode;
41
42
        return $this;
43
    }
44
45
    /**
46
     * @return string
47
     */
48 1
    public function getInnerHtml()
49
    {
50 1
        $innerHtml = '';
51
52 1
        if ($this->domNode) {
53 1
            foreach ($this->domNode->childNodes as $child) {
54 1
                $innerHtml .= static::htmlFromNode($child);
55
            }
56
        }
57
58 1
        return $innerHtml;
59
    }
60
61
    /**
62
     * @param string $name
63
     *
64
     * @return string
65
     */
66 1
    public function getAttribute($name)
67
    {
68 1
        return $this->domNode->getAttribute($name);
69
    }
70
71
    /**
72
     * @param \DOMDocument $domDocument
73
     *
74
     * @return \DOMElement
75
     */
76 1
    public function cloneNode(\DOMDocument $domDocument)
77
    {
78 1
        return $domDocument->importNode($this->getDomNode()->cloneNode(false), false);
79
    }
80
81
    /**
82
     * @param \DOMElement $node
83
     *
84
     * @return string
85
     */
86 1 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...
87
    {
88 1
        $domDocument = new \DOMDocument();
89 1
        $newNode = $domDocument->importNode($node, true);
90 1
        $domDocument->appendChild($newNode);
91
92 1
        return trim($domDocument->saveHTML());
93
    }
94
}
95