Skip to content

Commit f872c7e

Browse files
committed
1.x tweaks
1 parent 734635a commit f872c7e

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/HttpMessage/AssertionTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,22 @@ trait AssertionTrait
4343
* @param mixed $value The value to check.
4444
* @param string $what The name of the value.
4545
* @param bool $allowNumeric Allow float or int?
46+
* @param bool $allowNull Allow null?
4647
*
4748
* @return void
4849
*
4950
* @throws InvalidArgumentException
5051
*
5152
* @psalm-assert string $value
5253
*/
53-
protected function assertString($value, string $what = '', bool $allowNumeric = false): void
54+
protected function assertString($value, string $what = '', bool $allowNumeric = false, $allowNull = false): void
5455
{
5556
if (\is_string($value)) {
5657
return;
5758
}
59+
if ($allowNull && $value === null) {
60+
return;
61+
}
5862
if ($allowNumeric && \is_numeric($value)) {
5963
return;
6064
}

src/HttpMessage/Uri.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ public function withScheme(string $scheme): UriInterface
311311
*/
312312
public function withUserInfo(string $user, ?string $password = null): UriInterface
313313
{
314-
$this->assertString($user, 'user');
314+
$this->assertString($user, 'user', true);
315+
$this->assertString($password, 'password', true, true);
315316
$userInfo = (string) $user; // for versions without type hint in method signature
316317
$password = (string) $password; // for versions without type hint in method signature
317318
if ($userInfo !== '' && $password !== '') {
318-
$this->assertString($password, 'password');
319319
$userInfo .= ':' . $password;
320320
}
321321
if ($userInfo === $this->userInfo) {
@@ -417,7 +417,7 @@ public function withPath(string $path): UriInterface
417417
*/
418418
public function withQuery(string $query): UriInterface
419419
{
420-
$this->assertString($query, 'query');
420+
$this->assertString($query, 'query', true);
421421
$query = $this->filterQueryAndFragment($query);
422422
if ($query === $this->query) {
423423
return $this;

0 commit comments

Comments
 (0)