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.

FacebookChannel::send()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 15
cp 0
rs 9.6
c 0
b 0
f 0
cc 4
nc 6
nop 2
crap 20
1
<?php
2
3
namespace NotificationChannels\Facebook;
4
5
use GuzzleHttp\Exception\GuzzleException;
6
use Illuminate\Notifications\Notification;
7
use NotificationChannels\Facebook\Exceptions\CouldNotCreateMessage;
8
use NotificationChannels\Facebook\Exceptions\CouldNotSendNotification;
9
10
/**
11
 * Class FacebookChannel.
12
 */
13
class FacebookChannel
14
{
15
    /** @var Facebook */
16
    private $fb;
17
18
    /**
19
     * FacebookChannel constructor.
20
     *
21
     * @param  Facebook  $fb
22
     */
23
    public function __construct(Facebook $fb)
24
    {
25
        $this->fb = $fb;
26
    }
27
28
    /**
29
     * Send the given notification.
30
     *
31
     * @param  mixed         $notifiable
32
     * @param  Notification  $notification
33
     *
34
     * @return array
35
     *
36
     * @throws CouldNotCreateMessage
37
     * @throws CouldNotSendNotification
38
     * @throws GuzzleException
39
     */
40
    public function send($notifiable, Notification $notification): array
41
    {
42
        $message = $notification->toFacebook($notifiable);
0 ignored issues
show
Bug introduced by
The method toFacebook() 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...
43
44
        if (is_string($message)) {
45
            $message = FacebookMessage::create($message);
46
        }
47
48
        if ($message->toNotGiven()) {
49
            if (! $to = $notifiable->routeNotificationFor('facebook')) {
50
                throw CouldNotCreateMessage::recipientNotProvided();
51
            }
52
53
            $message->to($to);
54
        }
55
56
        $response = $this->fb->send($message->toArray());
57
58
        return json_decode($response->getBody()->getContents(), true);
59
    }
60
}
61