Skip to content

Commit

Permalink
Casting null values to empty "" in Uri various getter methods.
Browse files Browse the repository at this point in the history
Defaulting to null values in UriFactory if no scheme or host was provided.
  • Loading branch information
brentscheffler committed Oct 18, 2022
1 parent c773fc8 commit d36fe0b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/Factory/UriFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ public function createUri(string $uri = ""): UriInterface
*/
public static function createFromString(string $uri): Uri
{
// Parse the URI
$uriPart = \parse_url($uri);

if( $uriPart === false ){
throw new RuntimeException("Malformed URL string.");
}

return new Uri(
!empty($uriPart["scheme"]) ? \strtolower($uriPart["scheme"]) : "http",
!empty($uriPart["host"]) ? \strtolower($uriPart["host"]) : "",
!empty($uriPart["scheme"]) ? \strtolower($uriPart["scheme"]) : null,
!empty($uriPart["host"]) ? \strtolower($uriPart["host"]) : null,
$uriPart["path"] ?? null,
!empty($uriPart["port"]) ? $uriPart["port"] : null,
$uriPart["user"] ?? null,
Expand Down
6 changes: 3 additions & 3 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
*/
public function getScheme(): string
{
return $this->scheme;
return $this->scheme ?? "";
}

/**
Expand All @@ -40,7 +40,7 @@ public function getAuthority(): string
"%s:%s@%s:%s",
$this->username ?? "",
$this->password ?? "",
$this->host,
$this->host ?? "",
$this->port ?? ""
);
}
Expand Down Expand Up @@ -68,7 +68,7 @@ public function getUserInfo(): string
*/
public function getHost(): string
{
return $this->host;
return $this->host ?? "";
}

/**
Expand Down

0 comments on commit d36fe0b

Please sign in to comment.