Skip to content

Commit 37b7fbd

Browse files
Merge pull request #15
Filling headers with empty values is excluded
2 parents 9ef8278 + 8867b23 commit 37b7fbd

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/TrackerRequest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public function userId(int|string|null $id): static
2626
return $this;
2727
}
2828

29-
public function getUserId(): string
29+
public function getUserId(): ?string
3030
{
3131
if ($id = $this->get($this->header->userId)) {
3232
return $id;
3333
}
3434

35-
return '0';
35+
return null;
3636
}
3737

3838
public function ip(?string $ip = null): static
@@ -44,7 +44,7 @@ public function ip(?string $ip = null): static
4444
return $this;
4545
}
4646

47-
public function getIp(): string
47+
public function getIp(): ?string
4848
{
4949
if ($ip = $this->get($this->header->ip)) {
5050
return $ip;
@@ -88,6 +88,10 @@ public function getRequest(): Request
8888

8989
protected function set(string $key, array|int|string|null $value): static
9090
{
91+
if (! is_int($value) && ! $value) {
92+
return $this;
93+
}
94+
9195
if (is_int($value)) {
9296
$value = (string) $value;
9397
}

tests/Unit/Request/UserIdTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// 4) getUserId() returns '0' when nothing present
3232
$request = makeRequest();
3333
$telemetry = new TrackerRequest($request, $header);
34-
expect($telemetry->getUserId())->toBe('0');
34+
expect($telemetry->getUserId())->toBeNull();
3535
});

0 commit comments

Comments
 (0)