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

AbstractTableElement::getAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
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
/**
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
    {
69
        return $this->domNode->getAttribute($name);
70
    }
71
72
    /**
73
     * @param \DOMDocument $domDocument
74
     *
75
     * @return \DOMElement
76
     */
77
    public function cloneNode(\DOMDocument $domDocument)
78
    {
79
        return $domDocument->importNode($this->getDomNode()->cloneNode(false), false);
80
    }
81
82
    /**
83
     * @param \DOMElement $node
84
     *
85
     * @return string
86
     */
87 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...
88
    {
89
        $domDocument = new \DOMDocument();
90
        $newNode = $domDocument->importNode($node, true);
91
        $domDocument->appendChild($newNode);
92
        return trim($domDocument->saveHTML());
93
    }
94
}
95