Skip to content

Commit 47dc383

Browse files
committed
refactor: polish URI query helper types
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent 1c0fd68 commit 47dc383

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

system/HTTP/URI.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -876,15 +876,11 @@ public function addQuery(string $key, $value = null)
876876
}
877877

878878
/**
879-
* Return an instance with one query var added or replaced.
879+
* Returns an instance with one query var added or replaced.
880880
*
881881
* Note: Method not in PSR-7
882-
*
883-
* @param int|string|null $value
884-
*
885-
* @return static
886882
*/
887-
public function withQueryVar(string $key, $value)
883+
public function withQueryVar(string $key, int|string|null $value): static
888884
{
889885
$uri = clone $this;
890886

@@ -894,15 +890,13 @@ public function withQueryVar(string $key, $value)
894890
}
895891

896892
/**
897-
* Return an instance with multiple query vars added or replaced.
893+
* Returns an instance with multiple query vars added or replaced.
898894
*
899895
* Note: Method not in PSR-7
900896
*
901897
* @param array<string, int|string|null> $params
902-
*
903-
* @return static
904898
*/
905-
public function withQueryVars(array $params)
899+
public function withQueryVars(array $params): static
906900
{
907901
$uri = clone $this;
908902

tests/system/HTTP/URITest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ public function testWithQueryVarAddsQueryVarWithoutMutatingOriginal(): void
842842

843843
$new = $uri->withQueryVar('bar', 'baz');
844844

845+
$this->assertNotSame($uri, $new);
845846
$this->assertSame('http://example.com/foo?bar=baz', (string) $new);
846847
$this->assertSame('http://example.com/foo', (string) $uri);
847848
}
@@ -853,6 +854,7 @@ public function testWithQueryVarReplacesQueryVarAndPreservesFragment(): void
853854

854855
$new = $uri->withQueryVar('bar', 'foz');
855856

857+
$this->assertNotSame($uri, $new);
856858
$this->assertSame('http://example.com/foo?bar=foz#section', (string) $new);
857859
$this->assertSame('http://example.com/foo?bar=baz#section', (string) $uri);
858860
}
@@ -864,6 +866,7 @@ public function testWithQueryVarKeepsEmptyStringQueryVar(): void
864866

865867
$new = $uri->withQueryVar('bar', '');
866868

869+
$this->assertNotSame($uri, $new);
867870
$this->assertSame('http://example.com/foo?bar=', (string) $new);
868871
$this->assertSame('http://example.com/foo?bar=baz', (string) $uri);
869872
}
@@ -878,6 +881,7 @@ public function testWithQueryVarsAddsAndReplacesWithoutMutatingOriginal(): void
878881
'new' => 'value',
879882
]);
880883

884+
$this->assertNotSame($uri, $new);
881885
$this->assertSame('http://example.com/foo?foo=bar&bar=baz&baz=updated&new=value#section', (string) $new);
882886
$this->assertSame('http://example.com/foo?foo=bar&bar=baz&baz=foz#section', (string) $uri);
883887
}

0 commit comments

Comments
 (0)