Total Complexity | 5 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 |
|
54 | } |
||
55 | } |
||
56 |