Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Aug 29, 2023
1 parent 7d040e5 commit 4c8db99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion resources/views/livewire/usage.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class="rounded-md border-gray-200 text-gray-700 py-1 text-sm"
{{ $userRequestCount['user']['name'] }}
</div>
<div class="text-xs text-gray-500 truncate">
{{ $userRequestCount['user']['email'] }}
{{ $userRequestCount['user']['extra'] }}
</div>
</div>
</div>
Expand Down
22 changes: 17 additions & 5 deletions src/Pulse.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Pulse
/**
* The users resolver.
*
* @var ?(callable(\Illuminate\Support\Collection<int, string|int>): iterable<int, array{id: int|string, name: string, 'email'?: ?string}>)
* @var ?(callable(\Illuminate\Support\Collection<int, string|int>): iterable<int, array{id: int|string, name: string, 'extra'?: ?string}>)
*/
protected $usersResolver = null;

Expand Down Expand Up @@ -274,7 +274,7 @@ protected function shouldRecord(Entry|Update $entry): bool
/**
* Resolve the user's details using the given closure.
*
* @param (callable(\Illuminate\Support\Collection<int, string|int>): iterable<int, array{id: int|string, name: string, 'email'?: ?string}>) $callback
* @param (callable(\Illuminate\Support\Collection<int, string|int>): iterable<int, array{id: int|string, name: string, 'extra'?: ?string}>) $callback
*/
public function resolveUsersUsing(callable $callback): self
{
Expand All @@ -287,7 +287,7 @@ public function resolveUsersUsing(callable $callback): self
* Resolve the user's details using the given closure.
*
* @param \Illuminate\Support\Collection<int, string|int> $ids
* @return \Illuminate\Support\Collection<int, array{id: string|int, name: string, 'email'?: ?string}>
* @return \Illuminate\Support\Collection<int, array{id: string|int, name: string, 'extra'?: ?string}>
*/
public function resolveUsers(Collection $ids): Collection
{
Expand All @@ -296,11 +296,23 @@ public function resolveUsers(Collection $ids): Collection
}

if (class_exists(\App\Models\User::class)) {
return \App\Models\User::whereKey($ids)->get(['id', 'name', 'email']);
return \App\Models\User::whereKey($ids)
->get(['id', 'name', 'email'])
->map(fn (User $user) => [

Check failure on line 301 in src/Pulse.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Parameter $user of anonymous function has invalid type Laravel\Pulse\User.
'id' => $user->id,

Check failure on line 302 in src/Pulse.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Access to property $id on an unknown class Laravel\Pulse\User.
'name' => $user->name,

Check failure on line 303 in src/Pulse.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Access to property $name on an unknown class Laravel\Pulse\User.
'extra' => $user->email,

Check failure on line 304 in src/Pulse.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Access to property $email on an unknown class Laravel\Pulse\User.
]);
}

if (class_exists(\App\User::class)) {
return \App\User::whereKey($ids)->get(['id', 'name', 'email']);
return \App\User::whereKey($ids)
->get(['id', 'name', 'email'])
->map(fn (User $user) => [

Check failure on line 311 in src/Pulse.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Parameter $user of anonymous function has invalid type Laravel\Pulse\User.
'id' => $user->id,

Check failure on line 312 in src/Pulse.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Access to property $id on an unknown class Laravel\Pulse\User.
'name' => $user->name,

Check failure on line 313 in src/Pulse.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Access to property $name on an unknown class Laravel\Pulse\User.
'extra' => $user->email,

Check failure on line 314 in src/Pulse.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Access to property $email on an unknown class Laravel\Pulse\User.
]);
}

return $ids->map(fn (string|int $id) => [

Check failure on line 318 in src/Pulse.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Method Laravel\Pulse\Pulse::resolveUsers() should return Illuminate\Support\Collection<int, array{id: int|string, name: string, extra?: string|null}> but returns Illuminate\Support\Collection<int, array{id: int|string, name: string}>.
Expand Down
7 changes: 3 additions & 4 deletions src/Queries/Usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
/**
* Run the query.
*
* @return \Illuminate\Support\Collection<int, array{count: int, user: array{name: string, 'email': ?string}}>
* @return \Illuminate\Support\Collection<int, array{count: int, user: array{name: string, 'extra': ?string}}>
*/
public function __invoke(Interval $interval, string $type): Collection
{
Expand Down Expand Up @@ -61,9 +61,8 @@ public function __invoke(Interval $interval, string $type): Collection
'count' => (int) $row->count,
'user' => [
'name' => $user['name'],
// "extra" rather than 'email'
'email' => $user['email'] ?? null,
'avatar' => $user['avatar'] ?? null,
'extra' => $user['extra'] ?? $user['email'],
'avatar' => $user['avatar'] ?? ($user['email'] ?? false) ? "https://unavatar.io/{$user['email']}?fallback=".rawurlencode("https://source.boringavatars.com/marble/120/{$user['email']}?colors=2f2bad,ad2bad,e42692,f71568,f7db15") : null,
],
] : null;
})
Expand Down

0 comments on commit 4c8db99

Please sign in to comment.