Completed
Push — master ( 41fe5e...7c8927 )
by recca
01:56
created

Every8dChannel::send()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 18
ccs 0
cts 12
cp 0
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 10
nc 3
nop 2
crap 12
1
<?php
2
3
namespace Recca0120\Every8d;
4
5
use Illuminate\Notifications\Notification;
6
7
class Every8dChannel
8
{
9
    /**
10
     * $client.
11
     *
12
     * @var \Recca0120\Every8d\Client
13
     */
14
    protected $client;
15
16
    /**
17
     * __construct.
18
     *
19
     * @param \Recca0120\Every8d\Client $client
20
     */
21
    public function __construct(Client $client)
22
    {
23
        $this->client = $client;
24
    }
25
26
    /**
27
     * Send the given notification.
28
     *
29
     * @param mixed $notifiable
30
     * @param \Illuminate\Notifications\Notification $notification
31
     * @return \Recca0120\Every8d\Every8dMessage
32
     */
33
    public function send($notifiable, Notification $notification)
34
    {
35
        if (! $to = $notifiable->routeNotificationFor('every8d')) {
36
            return;
37
        }
38
39
        $message = $notification->toEvery8d($notifiable);
40
41
        if (is_string($message)) {
42
            $message = new Every8dMessage($message);
43
        }
44
45
        return $this->client->send([
46
            'subject' => $message->subject,
47
            'to' => $to,
48
            'text' => trim($message->content),
49
        ]);
50
    }
51
}
52