Completed
Pull Request — master (#49)
by Daniel
01:41 queued 10s
created

HtmlNode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

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