These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace PragmaRX\Health\Listeners; |
||
4 | |||
5 | use Illuminate\Support\Facades\Notification; |
||
6 | use PragmaRX\Health\Events\RaiseHealthIssue; |
||
7 | use PragmaRX\Health\Notifications\HealthStatus; |
||
8 | |||
9 | class NotifyHealthIssue |
||
10 | { |
||
11 | /** |
||
12 | * @return static |
||
13 | */ |
||
14 | private function getNotifiableUsers() |
||
15 | { |
||
16 | return collect(config('health.notifications.users.emails'))->map( |
||
17 | function ($item) { |
||
18 | $model = instantiate( |
||
19 | config('health.notifications.users.model') |
||
20 | ); |
||
21 | |||
22 | $model->email = $item; |
||
23 | |||
24 | return $model; |
||
25 | } |
||
26 | ); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Handle the event. |
||
31 | * |
||
32 | * @param RaiseHealthIssue $event |
||
33 | * @return void |
||
34 | */ |
||
35 | public function handle(RaiseHealthIssue $event) |
||
36 | { |
||
37 | try { |
||
38 | $event->failure->targets->each(function ($target) use ($event) { |
||
39 | if (! $target->result->healthy) { |
||
40 | Notification::send( |
||
41 | $this->getNotifiableUsers(), |
||
42 | new HealthStatus($target, $event->channel) |
||
43 | ); |
||
44 | } |
||
45 | }); |
||
46 | } catch (\Exception $exception) { |
||
47 | report($exception); |
||
48 | } catch (\Throwable $error) { |
||
49 | report($error); |
||
0 ignored issues
–
show
|
|||
50 | } |
||
51 | } |
||
52 | } |
||
53 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.