Completed
Push — master ( 94c2bc...39e215 )
by Dev
02:26
created

Link   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
wmc 11
eloc 18
dl 0
loc 51
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0

7 Methods

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