1 | <?php |
||||
2 | |||||
3 | namespace Honeybadger\HoneybadgerLaravel\Breadcrumbs; |
||||
4 | |||||
5 | use Honeybadger\HoneybadgerLaravel\Facades\Honeybadger; |
||||
6 | use Illuminate\Redis\Events\CommandExecuted; |
||||
7 | |||||
8 | /** |
||||
9 | * Note that Laravel only dispatches Redis events if the user calls Redis::enableEvents() first. |
||||
10 | */ |
||||
11 | class RedisCommandExecuted extends Breadcrumb |
||||
12 | { |
||||
13 | public $handles = CommandExecuted::class; |
||||
14 | |||||
15 | public function handleEvent(CommandExecuted $event) |
||||
16 | { |
||||
17 | $metadata = [ |
||||
18 | 'connectionName' => $event->connectionName, |
||||
19 | 'command' => $this->formatCommand($event->command, $event->parameters), |
||||
20 | 'duration' => number_format($event->time, 2, '.', '').'ms', |
||||
21 | ]; |
||||
22 | |||||
23 | Honeybadger::addBreadcrumb('Redis command executed', $metadata, 'query'); |
||||
24 | } |
||||
25 | |||||
26 | private function formatCommand(string $command, array $parameters) |
||||
27 | { |
||||
28 | $parameters = collect($parameters)->map(function ($parameter) { |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
29 | if (is_array($parameter)) { |
||||
30 | return collect($parameter)->map(function ($value, $key) { |
||||
0 ignored issues
–
show
$parameter of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
31 | if (is_array($value)) { |
||||
32 | return json_encode($value); |
||||
33 | } |
||||
34 | |||||
35 | return is_int($key) ? $value : "{$key} {$value}"; |
||||
36 | })->implode(' '); |
||||
37 | } |
||||
38 | |||||
39 | return $parameter; |
||||
40 | })->implode(' '); |
||||
41 | |||||
42 | return "{$command} {$parameters}"; |
||||
43 | } |
||||
44 | } |
||||
45 |