BroadcastChannel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 78.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 58
ccs 11
cts 14
cp 0.7856
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 6 1
A getData() 0 14 3
1
<?php
2
3
namespace Illuminate\Notifications\Channels;
4
5
use RuntimeException;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Contracts\Events\Dispatcher;
8
use Illuminate\Notifications\Events\BroadcastNotificationCreated;
9
10
class BroadcastChannel
11
{
12
    /**
13
     * The event dispatcher.
14
     *
15
     * @var \Illuminate\Contracts\Events\Dispatcher
16
     */
17
    protected $events;
18
19
    /**
20
     * Create a new database channel.
21
     *
22
     * @param  \Illuminate\Contracts\Events\Dispatcher  $events
23
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
24
     */
25 1
    public function __construct(Dispatcher $events)
26
    {
27 1
        $this->events = $events;
28 1
    }
29
30
    /**
31
     * Send the given notification.
32
     *
33
     * @param  mixed  $notifiable
34
     * @param  \Illuminate\Notifications\Notification  $notification
35
     * @return void
36
     */
37 1
    public function send($notifiable, Notification $notification)
38
    {
39 1
        $this->events->fire(new BroadcastNotificationCreated(
40 1
            $notifiable, $notification, $this->getData($notifiable, $notification)
41
        ));
42 1
    }
43
44
    /**
45
     * Get the data for the notification.
46
     *
47
     * @param  mixed  $notifiable
48
     * @param  \Illuminate\Notifications\Notification  $notification
49
     * @return array
50
     *
51
     * @throws \RuntimeException
52
     */
53 1
    protected function getData($notifiable, Notification $notification)
54
    {
55 1
        if (method_exists($notification, 'toBroadcast')) {
56
            return $notification->toBroadcast($notifiable);
0 ignored issues
show
Bug introduced by
The method toBroadcast() does not seem to exist on object<Illuminate\Notifications\Notification>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
        }
58
59 1
        if (method_exists($notification, 'toArray')) {
60 1
            return $notification->toArray($notifiable);
0 ignored issues
show
Bug introduced by
The method toArray() does not seem to exist on object<Illuminate\Notifications\Notification>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
        }
62
63
        throw new RuntimeException(
64
            'Notification is missing toArray method.'
65
        );
66
    }
67
}
68