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

Link::getElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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