Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/TrackerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public function userId(int|string|null $id): static
return $this;
}

public function getUserId(): string
public function getUserId(): ?string
{
if ($id = $this->get($this->header->userId)) {
return $id;
}

return '0';
return null;
}

public function ip(?string $ip = null): static
Expand All @@ -44,7 +44,7 @@ public function ip(?string $ip = null): static
return $this;
}

public function getIp(): string
public function getIp(): ?string
{
if ($ip = $this->get($this->header->ip)) {
return $ip;
Expand Down Expand Up @@ -88,6 +88,10 @@ public function getRequest(): Request

protected function set(string $key, array|int|string|null $value): static
{
if (! is_int($value) && ! $value) {
return $this;
}

if (is_int($value)) {
$value = (string) $value;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Request/UserIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// 4) getUserId() returns '0' when nothing present
$request = makeRequest();
$telemetry = new TrackerRequest($request, $header);
expect($telemetry->getUserId())->toBe('0');
expect($telemetry->getUserId())->toBeNull();
});