Test Failed
Push — master ( 13dcda...44dfad )
by Antonio Carlos
04:33
created

src/Listeners/NotifyHealthIssue.php (1 issue)

Upgrade to new PHP Analysis Engine

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 1
    private function getNotifiableUsers()
15
    {
16 1
        return collect(config('health.notifications.users.emails'))->map(
17
            function ($item) {
18 1
                $model = instantiate(
19 1
                    config('health.notifications.users.model')
20
                );
21
22 1
                $model->email = $item;
23
24 1
                return $model;
25 1
            }
26
        );
27
    }
28
29
    /**
30
     * Handle the event.
31
     *
32
     * @param  RaiseHealthIssue  $event
33
     * @return void
34
     */
35 1
    public function handle(RaiseHealthIssue $event)
36
    {
37
        try {
38
            $event->failure->targets->each(function ($target) use ($event) {
39 1
                if (!$target->result->healthy) {
40 1
                    Notification::send(
41 1
                        $this->getNotifiableUsers(),
42 1
                        new HealthStatus($target, $event->channel)
43
                    );
44
                }
45 1
            });
46 1
        } catch (\Exception $exception) {
47 1
            report($exception);
48
        } catch (\Throwable $error) {
49
            report($error);
0 ignored issues
show
$error of type object<Throwable> is not a sub-type of object<Exception>. It seems like you assume a concrete implementation of the interface Throwable to be always present.

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.

Loading history...
50
        }
51 1
    }
52
}
53