Completed
Push — master ( 4dd42e...7a1ec5 )
by Dev
12:19 queued 11:13
created

Link   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 95.83%

Importance

Changes 0
Metric Value
wmc 13
eloc 19
dl 0
loc 53
ccs 23
cts 24
cp 0.9583
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setAnchor() 0 6 3
A __construct() 0 7 2
A mayFollow() 0 9 4
A getUrl() 0 3 1
A getPageUrl() 0 3 1
A getElement() 0 3 1
A getAnchor() 0 3 1
1
<?php
2
3
namespace PiedWeb\UrlHarvester;
4
5
use simple_html_dom_node;
6
7
class Link
8
{
9
    private $url;
10
    private $anchor;
11
    private $element;
12
13 12
    public function __construct(string $url, ?simple_html_dom_node $element = null)
14
    {
15 12
        $this->url = trim($url);
16 12
        if (null !== $element) {
17 12
            $this->setAnchor($element);
18
        }
19 12
        $this->element = $element;
20 12
    }
21
22 12
    protected function setAnchor(simple_html_dom_node $element)
23
    {
24 12
        $this->anchor = substr(Helper::clean($element->plaintext), 0, 100);
25
26 12
        if (empty($this->anchor) && $element->find('*[alt]', 0)) {
27
            $this->anchor = substr(Helper::clean($element->find('*[alt]', 0)->alt), 0, 100);
28
        }
29 12
    }
30
31 9
    public function getUrl()
32
    {
33 9
        return $this->url;
34
    }
35
36 3
    public function getPageUrl()
37
    {
38 3
        return preg_replace('/(\#.*)/si', '', $this->url);
39
    }
40
41 3
    public function getAnchor()
42
    {
43 3
        return $this->anchor;
44
    }
45
46 3
    public function getElement()
47
    {
48 3
        return $this->element;
49
    }
50
51 6
    public function mayFollow()
52
    {
53 6
        if (isset($this->element) && isset($this->element->rel)) {
54 3
            if (false !== strpos($this->element->rel, 'nofollow')) {
55 3
                return false;
56
            }
57
        }
58
59 3
        return true;
60
    }
61
}
62