Skip to content

Commit

Permalink
Improve type casting
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jul 8, 2024
1 parent ae79f05 commit 754fe41
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 9 additions & 5 deletions components/Components/SchemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,18 @@ public static function getURIProvider(): iterable
public function it_can_detect_information_about_special_schemes(
?string $scheme,
bool $isHttp,
bool $isWebsocket,
bool $isSsl,
bool $isSpecial,
Port $defaultPort,
): void {
self::assertSame($isHttp, Scheme::new($scheme)->isHttp());
self::assertSame($isSsl, Scheme::new($scheme)->isSsl());
self::assertSame($isSpecial, Scheme::new($scheme)->isSpecial());
self::assertSame($defaultPort, Scheme::new($scheme)->defaultPort());
$schemeObject = Scheme::new($scheme);

self::assertSame($isHttp, $schemeObject->isHttp());
self::assertSame($isWebsocket, $schemeObject->isWebsocket());
self::assertSame($isSsl, $schemeObject->isSsl());
self::assertSame($isSpecial, $schemeObject->isSpecial());
self::assertSame($defaultPort, $schemeObject->defaultPort());
}

public static function getSchemeInfoProvider(): \Generator
Expand All @@ -135,7 +139,7 @@ public static function getSchemeInfoProvider(): \Generator
yield 'detect an WSS URL' => [
'scheme' => 'wss',
'isHttp' => false,
'isWebsocket' => false,
'isWebsocket' => true,
'isSsl' => true,
'isSpecial' => true,
Port::new(443),
Expand Down
11 changes: 6 additions & 5 deletions uri/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -1121,16 +1121,17 @@ public function withUserInfo(
Stringable|string|null $user,
#[SensitiveParameter] Stringable|string|null $password = null
): UriInterface {
$user = Encoder::encodeUser($this->filterString($user));
$password = Encoder::encodePassword($this->filterString($password));
$userInfo = ('' !== $user) ? $this->formatUserInfo($user, $password) : null;
$userInfo = ('' !== $user) ? $this->formatUserInfo(
Encoder::encodeUser($this->filterString($user)),
Encoder::encodePassword($this->filterString($password))
) : null;

return match ($userInfo) {
$this->userInfo => $this,
default => new self(
$this->scheme,
$user,
$password,
$user instanceof Stringable ? $user->__toString() : $user,
$password instanceof Stringable ? $password->__toString() : $password,
$this->host,
$this->port,
$this->path,
Expand Down

0 comments on commit 754fe41

Please sign in to comment.