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

HtmlNode::getNode()   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
use DOMDocument;
7
8
class HtmlNode
9
{
10
11
    /** @var \DOMElement */
12
    protected $node;
13
14
    /**
15
     * @param \DOMElement $node
16
     *
17
     * @return static
18
     */
19
    public static function create(DOMElement $node)
20
    {
21
        return new static($node);
22
    }
23
24
    public function __construct(DOMElement $node)
25
    {
26
      $this->node = $node;
27
    }
28
29
    /**
30
     * @param void
31
     *
32
     * @return \DOMElement
33
     */
34
    public function getNode(): DOMElement
35
    {
36
      return $this->node;
37
    }
38
39
    /**
40
     * @param void
41
     *
42
     * @return string
43
     */
44
    public function getHtml(): string
45
    {
46
        return $this->node->ownerDocument->saveHTML($this->node);
47
    }
48
49
    /**
50
     * @param void
51
     *
52
     * @return string
53
     */
54
    public function getHtmlAndUpdateHref(string $href): string
55
    {
56
        return $this->node->setAttribute('href', $href)->ownerDocument->saveHTML($this->node);
57
    }
58
59
}
60