GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DiscordChannel::send()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 21
ccs 12
cts 12
cp 1
crap 4
rs 9.9332
1
<?php
2
3
namespace NotificationChannels\Discord;
4
5
use Illuminate\Notifications\Notification;
6
7
class DiscordChannel
8
{
9
    /**
10
     * @var \NotificationChannels\Discord\Discord
11
     */
12
    protected $discord;
13
14
    /**
15
     * @param \NotificationChannels\Discord\Discord $discord
16
     */
17 2
    public function __construct(Discord $discord)
18
    {
19 2
        $this->discord = $discord;
20
    }
21
22
    /**
23
     * Send the given notification.
24
     *
25
     * @param mixed $notifiable
26
     * @param \Illuminate\Notifications\Notification $notification
27
     *
28
     * @return array
29
     *
30
     * @throws \NotificationChannels\Discord\Exceptions\CouldNotSendNotification
31
     */
32 2
    public function send($notifiable, Notification $notification)
33
    {
34 2
        if (! $channel = $notifiable->routeNotificationFor('discord', $notification)) {
35 1
            return;
36
        }
37
38 1
        $message = $notification->toDiscord($notifiable);
39
40 1
        $data = [
41 1
            'content' => $message->body
42 1
        ];
43
44 1
        if (count($message->embed) > 0) {
45 1
            $data['embeds'] = [$message->embed];
46
        }
47
48 1
        if (count($message->components) > 0) {
49 1
            $data['components'] = $message->components;
50
        }
51
52 1
        return $this->discord->send($channel, $data);
53
    }
54
}
55