Completed
Push — master ( f33ecc...f11cb1 )
by Dev
10:58 queued 09:04
created

Link::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
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 9
    public function __construct(string $url, $element)
12
    {
13 9
        $this->url = $url;
14 9
        $this->setAnchor($element);
15 9
        $this->element = $element;
16 9
    }
17
18 9
    protected function setAnchor($element)
19
    {
20 9
        $this->anchor = substr(Helper::clean($element->plaintext), 0, 100);
21
22 9
        if (empty($this->anchor) && $element->find('*[alt]', 0)) {
23
            $this->anchor = substr(Helper::clean($element->find('*[alt]', 0)->alt), 0, 100);
24
        }
25 9
    }
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