From b6de109e7fbea188da9a1c66cf920ba05e732774 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish Date: Thu, 23 Nov 2023 08:30:58 -0500 Subject: [PATCH 1/4] allow filterPort as string --- src/Uri.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Uri.php b/src/Uri.php index d589899..7269841 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -300,7 +300,13 @@ protected function hasStandardPort(): bool */ protected function filterPort($port): ?int { - if (is_null($port) || (is_integer($port) && ($port >= 1 && $port <= 65535))) { + if (is_null($port)) { + return null; + } + + $port = (int) $port; + + if ($port >= 1 && $port <= 65535) { return $port; } From 55e79ab06db8027f9da9511b290f82715077fca4 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish Date: Thu, 23 Nov 2023 08:36:27 -0500 Subject: [PATCH 2/4] add string-port test --- tests/UriTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/UriTest.php b/tests/UriTest.php index a0c4d28..f98fb2e 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -215,6 +215,13 @@ public function testWithPortInvalidString() $this->uriFactory()->withPort('Foo'); } + public function testWithPortIntegerAsString() + { + $uri = $this->uriFactory()->withPort("1"); + + $this->assertEquals(1, $uri->getPort()); + } + public function testGetPath() { $this->assertEquals('/foo/bar', $this->uriFactory()->getPath()); From 7cab19b265b8e378968eea2c27518be0cd17d6e4 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish <42181698+cosmastech@users.noreply.github.com> Date: Fri, 24 Nov 2023 20:33:25 -0500 Subject: [PATCH 3/4] modify test --- tests/UriTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/UriTest.php b/tests/UriTest.php index f98fb2e..92077ec 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -217,9 +217,9 @@ public function testWithPortInvalidString() public function testWithPortIntegerAsString() { - $uri = $this->uriFactory()->withPort("1"); + $uri = $this->uriFactory()->withPort("199"); - $this->assertEquals(1, $uri->getPort()); + $this->assertEquals(199, $uri->getPort()); } public function testGetPath() From 655fd1f5d2f68fc42c3bbaf4521bce9224a434cb Mon Sep 17 00:00:00 2001 From: Luke Kuzmish <42181698+cosmastech@users.noreply.github.com> Date: Sat, 2 Dec 2023 08:04:29 -0500 Subject: [PATCH 4/4] docblock typehint --- src/Uri.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Uri.php b/src/Uri.php index 7269841..6f51d7f 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -292,7 +292,7 @@ protected function hasStandardPort(): bool /** * Filter Uri port. * - * @param int|null $port The Uri port number. + * @param int|string|null $port The Uri port number. * * @return int|null *