| Total Complexity | 7 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Coverage | 86.67% |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | final class Url |
||
| 6 | { |
||
| 7 | /** @var string */ |
||
| 8 | private $value; |
||
| 9 | |||
| 10 | 11 | public function __construct(string $value) |
|
| 11 | { |
||
| 12 | 11 | if (!$this->validateUrl($value)) { |
|
| 13 | 1 | throw new \InvalidArgumentException(sprintf('URL "%s" is not supported', $value)); |
|
| 14 | } |
||
| 15 | |||
| 16 | 10 | $this->value = $value; |
|
| 17 | 10 | } |
|
| 18 | |||
| 19 | 11 | private function validateUrl(string $url): bool |
|
| 20 | { |
||
| 21 | // Validate SSH URLs |
||
| 22 | 11 | if (preg_match('/^git@[-a-z0-9\.]+:[\w-]+\/[\w-]+\.git$/', $url)) { |
|
| 23 | 7 | return true; |
|
| 24 | } |
||
| 25 | |||
| 26 | // Validate HTTP URLs |
||
| 27 | 6 | if (filter_var($url, FILTER_VALIDATE_URL)) { |
|
| 28 | 5 | return true; |
|
| 29 | } |
||
| 30 | |||
| 31 | 1 | return false; |
|
| 32 | } |
||
| 33 | |||
| 34 | public function getValue(): string |
||
| 37 | } |
||
| 38 | |||
| 39 | 8 | public function __toString() |
|
| 44 |