| Total Complexity | 5 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 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 | 9 | public function __construct(string $url, int $depth = 0) |
|
| 28 | { |
||
| 29 | 9 | if (!filter_var($url, FILTER_VALIDATE_URL)) { |
|
| 30 | 1 | throw new InvalidUrlException("Provided URL is invalid: {$url}"); |
|
| 31 | } |
||
| 32 | |||
| 33 | 8 | if ($depth < 0) { |
|
| 34 | 1 | throw new \InvalidArgumentException('Provided depth must be non negative'); |
|
| 35 | } |
||
| 36 | 7 | $this->url = $url; |
|
| 37 | 7 | $this->depth = $depth; |
|
| 38 | 7 | } |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @return string |
||
| 42 | */ |
||
| 43 | 7 | public function getUrl(): string |
|
| 44 | { |
||
| 45 | 7 | return $this->url; |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return int |
||
| 50 | */ |
||
| 51 | 7 | public function getDepth(): int |
|
| 54 | } |
||
| 55 | } |
||
| 56 |