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

AbstractTableElement::getInnerHtml()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
ccs 0
cts 8
cp 0
rs 9.4285
cc 3
eloc 6
nc 2
nop 0
crap 12
1
<?php
2
3
namespace Caxy\HtmlDiff\Table;
4
5
/**
6
 * Class AbstractTableElement
7
 * @package Caxy\HtmlDiff\Table
8
 */
9
abstract class AbstractTableElement
10
{
11
    /**
12
     * @var \DOMElement
13
     */
14
    protected $domNode;
15
16
    /**
17
     * AbstractTableElement constructor.
18
     *
19
     * @param \DOMElement|null $domNode
20
     */
21
    public function __construct(\DOMElement $domNode = null)
22
    {
23
        $this->domNode = $domNode;
24
    }
25
26
    /**
27
     * @return \DOMElement
28
     */
29
    public function getDomNode()
30
    {
31
        return $this->domNode;
32
    }
33
34
    /**
35
     * @param \DOMElement $domNode
36
     *
37
     * @return $this
38
     */
39
    public function setDomNode(\DOMElement $domNode)
40
    {
41
        $this->domNode = $domNode;
42
43
        return $this;
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getInnerHtml()
50
    {
51
        $innerHtml = '';
52
53
        if ($this->domNode) {
54
            foreach ($this->domNode->childNodes as $child) {
55
                $innerHtml .= static::htmlFromNode($child);
56
            }
57
        }
58
59
        return $innerHtml;
60
    }
61
62
    /**
63
     * @param string $name
64
     *
65
     * @return string
66
     */
67
    public function getAttribute($name) {
68
        return $this->domNode->getAttribute($name);
69
    }
70
71
    /**
72
     * @param \DOMElement $node
73
     *
74
     * @return string
75
     */
76 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...
77
    {
78
        $domDocument = new \DOMDocument();
79
        $newNode = $domDocument->importNode($node, true);
80
        $domDocument->appendChild($newNode);
81
        return trim($domDocument->saveHTML());
82
    }
83
}
84