LineChannel::send()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 13
cp 0
rs 9.7333
c 0
b 0
f 0
cc 4
nc 6
nop 2
crap 20
1
<?php
2
3
namespace NotificationChannels\Line;
4
5
use LINE\LINEBot;
6
use Illuminate\Notifications\Notification;
7
use LINE\LINEBot\Exception\CurlExecutionException;
8
use NotificationChannels\Line\Exceptions\CouldNotSendNotification;
9
10
class LineChannel
11
{
12
    /** @var \LINE\LINEBot */
13
    protected $line;
14
15
    /**
16
     * @param \LINE\LINEBot $line
17
     */
18
    public function __construct(LINEBot $line)
19
    {
20
        $this->line = $line;
21
    }
22
23
    /**
24
     * Send the given notification.
25
     *
26
     * @param mixed $notifiable
27
     * @param \Illuminate\Notifications\Notification $notification
28
     *
29
     * @throws \NotificationChannels\Line\Exceptions\CouldNotSendNotification
30
     */
31
    public function send($notifiable, Notification $notification)
32
    {
33
        $lineMessage = $notification->toLine($notifiable);
0 ignored issues
show
Bug introduced by
The method toLine() 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...
34
35
        $to = $notifiable->routeNotificationFor('line') ?: config('services.line.user_id');
36
37
        try {
38
            $response = $this->line->pushMessage($to, $lineMessage);
39
        } catch (CurlExecutionException $e) {
40
            throw CouldNotSendNotification::curlError($e);
41
        }
42
43
        if (! $response->isSucceeded()) {
44
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
45
        }
46
    }
47
}
48