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

HtmlNode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 52
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 4 1
A getNode() 0 4 1
A getHtml() 0 4 1
A getHtmlAndUpdateHref() 0 4 1
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