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

AbstractTableElement::getAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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