Passed
Push — main ( e2b24b...b1209d )
by PRATIK
04:16
created

AnnouncementMadeListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 3
1
<?php
2
3
namespace Adminetic\Announcement\Listeners;
4
5
use App\Models\User;
0 ignored issues
show
Bug introduced by
The type App\Models\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Support\Facades\Notification;
7
use Adminetic\Announcement\Events\AnnouncementMadeEvent;
8
use Adminetic\Announcement\Notifications\AnnouncementNotification;
9
use Adminetic\Announcement\Notifications\SlackAnnouncementNotification;
10
11
class AnnouncementMadeListener
12
{
13
    /**
14
     * Handle the event.
15
     *
16
     * @param  object  $event
17
     * @return void
18
     */
19
    public function handle(AnnouncementMadeEvent $event)
20
    {
21
        if (isset($event->announcement)) {
22
            $audiences  = User::find($event->announcement->audience);
23
            Notification::send($audiences, new AnnouncementNotification($event->announcement));
24
            if ($event->announcement->slack_notify) {
25
                $audiences->first()->setSlackUrl(env('SLACK_WEBHOOK', null))->notify(new SlackAnnouncementNotification($event->announcement));
26
            }
27
        }
28
    }
29
}
30