LineChannel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 38
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 16 4
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