BaseNotificationTrait::via()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 3
nop 1
1
<?php
2
namespace TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications;
3
4
trait BaseNotificationTrait
5
{
6
    /**
7
     * Get the notification's delivery channels by host or global if not exist.
8
     *
9
     * @param  mixed $notifiable
10
     * @return array
11
     */
12
    public function via($notifiable)
13
    {
14
        /* @var $event \Spatie\ServerMonitor\Events\Event */
15
        $event = $notifiable->getEvent();
16
        /* @var $host \Spatie\ServerMonitor\Models\Host */
17
        $host = $event->check->host()->first();
18
        $notifications = $host->getCustomProperty('notifications');
19
        if(!$notifications) {
20
            return config('server-monitor.notifications.notifications.'.static::class);
21
        }
22
        if(isset($notifications[static::class]) && isset($notifications[static::class]['channels'])) {
23
            return $notifications[static::class]['channels'];
24
        }
25
        return [];
26
    }
27
}
28