Link::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 3
rs 10
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 15
    public function __construct(string $url, int $depth = 0)
28
    {
29 15
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
30 1
            throw new InvalidUrlException("Provided URL is invalid: {$url}");
31
        }
32
33 14
        if ($depth < 0) {
34 1
            throw new \InvalidArgumentException('Provided depth must be non negative');
35
        }
36 13
        $this->url = $url;
37 13
        $this->depth = $depth;
38
    }
39
40
    /**
41
     * @return string
42
     */
43 13
    public function getUrl(): string
44
    {
45 13
        return $this->url;
46
    }
47
48
    /**
49
     * @return int
50
     */
51 13
    public function getDepth(): int
52
    {
53 13
        return $this->depth;
54
    }
55
}
56