Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
40 / 40 |
| Url | |
100.00% |
1 / 1 |
|
100.00% |
11 / 11 |
19 | |
100.00% |
40 / 40 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
9 / 9 |
|||
| getScheme | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getHost | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getPath | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getQuery | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getFragment | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getPort | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getUser | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getPassword | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| fromString | |
100.00% |
1 / 1 |
2 | |
100.00% |
15 / 15 |
|||
| isEqualTo | |
100.00% |
1 / 1 |
8 | |
100.00% |
8 / 8 |
|||
| <?php | |
| namespace Luxian\Type; | |
| class Url | |
| { | |
| /** @var string */ | |
| private $scheme; | |
| /** @var string */ | |
| private $host; | |
| /** @var string */ | |
| private $path; | |
| /** @var string */ | |
| private $query; | |
| /** @var string */ | |
| private $fragment; | |
| /** @var int */ | |
| private $port; | |
| /** @var string */ | |
| private $user; | |
| /** @var string */ | |
| private $password; | |
| public function __construct( | |
| string $scheme = '', | |
| string $host = '', | |
| string $path = '', | |
| string $query = '', | |
| string $fragment = '', | |
| int $port = 0, | |
| string $user = '', | |
| string $password = '' | |
| ) | |
| { | |
| $this->scheme = $scheme; | |
| $this->host = $host; | |
| $this->path = $path; | |
| $this->query = $query; | |
| $this->fragment = $fragment; | |
| $this->port = $port; | |
| $this->user = $user; | |
| $this->password = $password; | |
| } | |
| public function getScheme(): string | |
| { | |
| return $this->scheme; | |
| } | |
| public function getHost(): string | |
| { | |
| return $this->host; | |
| } | |
| public function getPath(): string | |
| { | |
| return $this->path; | |
| } | |
| public function getQuery(): string | |
| { | |
| return $this->query; | |
| } | |
| public function getFragment(): string | |
| { | |
| return $this->fragment; | |
| } | |
| public function getPort(): int | |
| { | |
| return $this->port; | |
| } | |
| public function getUser(): string | |
| { | |
| return $this->user; | |
| } | |
| public function getPassword(): string | |
| { | |
| return $this->password; | |
| } | |
| public static function fromString(string $url): Url | |
| { | |
| $parts = parse_url($url); | |
| if ($parts === false) { | |
| $message = 'Trying to create URL from invalid string: "%s"'; | |
| throw new \InvalidArgumentException(sprintf($message, $url)); | |
| } | |
| $defaults = [ | |
| 'scheme' => '', | |
| 'host' => '', | |
| 'port' => 0, | |
| 'path' => '', | |
| 'query' => '', | |
| 'fragment' => '', | |
| 'user' => '', | |
| 'pass' => '', | |
| ]; | |
| $parts = array_merge($defaults, $parts); | |
| return new static( | |
| $parts['scheme'], | |
| $parts['host'], | |
| $parts['path'], | |
| $parts['query'], | |
| $parts['fragment'], | |
| $parts['port'], | |
| $parts['user'], | |
| $parts['pass'], | |
| ); | |
| } | |
| public function isEqualTo(Url $url): bool | |
| { | |
| return $this->scheme === $url->getScheme() | |
| && $this->host === $url->getHost() | |
| && $this->path === $url->getPath() | |
| && $this->query === $url->getQuery() | |
| && $this->fragment === $url->getFragment() | |
| && $this->port === $url->getPort() | |
| && $this->user === $url->getUser() | |
| && $this->password === $url->getPassword(); | |
| } | |
| } |