Completed
Push — master ( 1494d2...398a9b )
by dan
02:07
created

Broadcaster::__construct()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.5906
c 0
b 0
f 0
cc 5
eloc 14
nc 5
nop 3
1
<?php
2
3
namespace IrishDan\NotificationBundle\Broadcast;
4
5
use IrishDan\NotificationBundle\Channel\ChannelInterface;
6
use IrishDan\NotificationBundle\Notification\NotificationInterface;
7
8
class Broadcaster
9
{
10
    protected $notifiable;
11
    protected $channel;
12
    protected $config;
13
    protected $channelName;
14
15
    public function __construct(BroadcastNotifiableInterface $notifiable, ChannelInterface $channel, array $config)
16
    {
17
        $this->notifiable = $notifiable;
18
        $this->channel = $channel;
19
        $this->config = $config;
20
        $this->channelName = $channel->channelName();
21
22
        switch ($this->channelName) {
23
            case 'slack':
24
                // Set the data for Slack Broadcasts
25
                if (!empty($config['webhook'])) {
26
                    $notifiable->setSlackWebhook($config['webhook']);
27
                }
28
                break;
29
30
            case 'pusher':
31
                // Set data for pusher broadcasts
32
                if (!empty($config['channel_name'])) {
33
                    $notifiable->setPusherChannel($config['channel_name']);
34
                }
35
                break;
36
        }
37
    }
38
39
    public function send(NotificationInterface $notification)
40
    {
41
        $notification->setNotifiable($this->notifiable);
0 ignored issues
show
Documentation introduced by
$this->notifiable is of type object<IrishDan\Notifica...astNotifiableInterface>, but the function expects a object<IrishDan\Notifica...on\NotifiableInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
        $notification->setChannel($this->channelName);
43
44
        // Format and send the broadcast
45
        $message = $this->channel->format($notification);
0 ignored issues
show
Bug introduced by
The method format() does not exist on IrishDan\NotificationBun...hannel\ChannelInterface. Did you maybe mean formatAndDispatch()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
46
        $this->channel->dispatch($message);
0 ignored issues
show
Bug introduced by
The method dispatch() does not exist on IrishDan\NotificationBun...hannel\ChannelInterface. Did you maybe mean formatAndDispatch()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
47
    }
48
}