Passed
Pull Request — master (#31)
by Josh
03:43
created

AbstractTableElement::getAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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