Skip to content

Commit

Permalink
Improve Typehinting
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jul 30, 2023
1 parent 037b0c0 commit e1d8d33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
18 changes: 4 additions & 14 deletions Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,11 @@ final class Http implements Stringable, Psr7UriInterface, JsonSerializable
{
private function __construct(private readonly UriInterface $uri)
{
$this->validate($this->uri);
}

/**
* Validate the submitted uri against PSR-7 UriInterface.
*
* @throws SyntaxError if the given URI does not follow PSR-7 UriInterface rules
*/
private function validate(UriInterface $uri): void
{
if (null === $uri->getScheme() && '' === $uri->getHost()) {
if (null === $this->uri->getScheme() && '' === $this->uri->getHost()) {
throw new SyntaxError('An URI without scheme can not contains a empty host string according to PSR-7: '.$uri);
}

$port = $uri->getPort();
$port = $this->uri->getPort();
if (null !== $port && ($port < 0 || $port > 65535)) {
throw new SyntaxError('The URI port is outside the established TCP and UDP port ranges: '.$uri);
}
Expand Down Expand Up @@ -81,7 +71,7 @@ public static function fromServer(array $server): self
*
* The returned URI must be absolute.
*/
public static function fromBaseUri(Stringable|String $uri, Stringable|String|null $baseUri = null): self
public static function fromBaseUri(Stringable|string $uri, Stringable|string|null $baseUri = null): self
{
return new self(Uri::fromBaseUri($uri, $baseUri));
}
Expand Down Expand Up @@ -265,7 +255,7 @@ public static function createFromUri(Psr7UriInterface|UriInterface $uri): self
*
* The returned URI must be absolute.
*/
public static function createFromBaseUri(Stringable|String $uri, Stringable|String|null $baseUri = null): self
public static function createFromBaseUri(Stringable|string $uri, Stringable|string|null $baseUri = null): self
{
return self::fromBaseUri($uri, $baseUri);
}
Expand Down
2 changes: 1 addition & 1 deletion Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public static function new(Stringable|string $uri = ''): self
*
* The returned URI must be absolute.
*/
public static function fromBaseUri(Stringable|String $uri, Stringable|String|null $baseUri = null): self
public static function fromBaseUri(Stringable|string $uri, Stringable|string|null $baseUri = null): self
{
$uri = self::new((string) $uri);
$baseUri = BaseUri::from($baseUri ?? $uri);
Expand Down

0 comments on commit e1d8d33

Please sign in to comment.