FlockChannel::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace NotificationChannels\Flock;
4
5
use Illuminate\Notifications\Notification;
6
use NotificationChannels\Flock\Exceptions\CouldNotSendNotification;
7
8
class FlockChannel
9
{
10
    /**
11
     * Flock instance.
12
     *
13
     * @var Flock
14
     */
15
    protected $flock;
16
17
    /**
18
     * FlockChannel constructor.
19
     *
20
     * @param Flock $flock
21
     */
22 2
    public function __construct(Flock $flock)
23
    {
24 2
        $this->flock = $flock;
25 2
    }
26
27
    /**
28
     * Send the given notification.
29
     *
30
     * @param mixed $notifiable
31
     * @param \Illuminate\Notifications\Notification $notification
32
     *
33
     * @throws \NotificationChannels\Flock\Exceptions\CouldNotSendNotification
34
     */
35 2
    public function send($notifiable, Notification $notification)
36
    {
37 2
        $message = $notification->toFlock($notifiable);
0 ignored issues
show
Bug introduced by
The method toFlock() 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...
38
39 2
        if (is_string($message)) {
40
            $message = FlockMessage::create($message);
41
        }
42
43 2
        if (! $notifiable->routeNotificationFor('flock')) {
44 1
            throw CouldNotSendNotification::flockRouteNotProvided();
45
        }
46
47 1
        $url = $notifiable->routeNotificationFor('flock');
48 1
        $params = $message->toArray();
49
50 1
        $this->flock->sendMessage($url, $params);
51 1
    }
52
}
53