Test Setup Failed
Pull Request — master (#3)
by Radosław
03:11
created

Link::getUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Radowoj\Crawla\Link;
6
7
use Radowoj\Crawla\Exception\InvalidUrlException;
8
9
class Link
10
{
11
    /**
12
     * @var string
13
     */
14
    private $url;
15
16
    /**
17
     * @var int
18
     */
19
    private $depth;
20
21
    /**
22
     * Link constructor.
23
     *
24
     * @param string $url
25
     * @param int    $depth
26
     */
27
    public function __construct(string $url, int $depth = 0)
28
    {
29
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
30
            throw new InvalidUrlException("Provided URL is invalid: {$url}");
31
        }
32
33
        if ($depth < 0) {
34
            throw new \InvalidArgumentException('Provided depth must be non negative');
35
        }
36
        $this->url = $url;
37
        $this->depth = $depth;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getUrl(): string
44
    {
45
        return $this->url;
46
    }
47
48
    /**
49
     * @return int
50
     */
51
    public function getDepth(): int
52
    {
53
        return $this->depth;
54
    }
55
}
56