Skip to content

Commit a170dab

Browse files
committed
less stupid, but its still stupid.
1 parent 707ce40 commit a170dab

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/HttpAuth.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222

2323
class HttpAuth implements \JsonSerializable
2424
{
25-
private const FIELD_USERNAME = 'username';
26-
private const FIELD_PASSWORD = 'password';
27-
28-
public string $username = '';
29-
public string $password = '';
25+
public string $username;
26+
public string $password;
3027

3128
public function __construct(string $username = '', string $password = '')
3229
{
@@ -49,18 +46,23 @@ public function compileAuthString(): string
4946
return (string)$this;
5047
}
5148

52-
public function jsonSerialize(): array
49+
public function jsonSerialize(): \stdClass
5350
{
54-
return [self::FIELD_USERNAME => $this->username, self::FIELD_PASSWORD => $this->password];
51+
$out = new \stdClass();
52+
$out->username = $this->username;
53+
if ('' !== $this->password) {
54+
$out->password = $this->password;
55+
}
56+
return $out;
5557
}
5658

5759
public function __debugInfo(): array
5860
{
59-
return [self::FIELD_USERNAME => $this->username];
61+
return ['username' => $this->username];
6062
}
6163

6264
public function __toString(): string
6365
{
64-
return trim(sprintf('%s:%s', $this->username, $this->password), ':');
66+
return $this->password !== '' ? "{$this->username}:{$this->password}" : $this->username;
6567
}
6668
}

0 commit comments

Comments
 (0)