Completed
Pull Request — master (#49)
by Daniel
01:31
created

HtmlNode::getHtml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\Crawler;
4
5
use DOMElement;
6
7
class HtmlNode
8
{
9
10
    /** @var \DOMElement */
11
    protected $node;
12
13
    /**
14
     * @param \DOMElement $node
15
     *
16
     * @return static
17
     */
18
    public static function create(DOMElement $node)
19
    {
20
        return new static($node);
21
    }
22
23
    public function __construct(DOMElement $node)
24
    {
25
        $this->node = $node;
26
    }
27
28
    /**
29
     * @param void
30
     *
31
     * @return \DOMElement
32
     */
33
    public function getNode(): DOMElement
34
    {
35
        return $this->node;
36
    }
37
38
    /**
39
     * @param void
40
     *
41
     * @return string
42
     */
43
    public function getHtml(): string
44
    {
45
        return $this->node->ownerDocument->saveHTML($this->node);
46
    }
47
48
    /**
49
     * @param void
50
     *
51
     * @return string
52
     */
53
    public function getHtmlAndUpdateHref(string $href): string
54
    {
55
        return $this->node->setAttribute('href', $href)->ownerDocument->saveHTML($this->node);
56
    }
57
58
}
59