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.
Completed
Pull Request — master (#27)
by
unknown
03:25
created

TwitterChannel::send()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5.0488

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
ccs 14
cts 16
cp 0.875
rs 8.5906
cc 5
eloc 12
nc 8
nop 2
crap 5.0488
1
<?php
2
3
namespace NotificationChannels\Twitter;
4
5
use Abraham\TwitterOAuth\TwitterOAuth;
6
use Illuminate\Notifications\Notification;
7
use NotificationChannels\Twitter\Exceptions\CouldNotSendNotification;
8
9
class TwitterChannel
10
{
11
12
    /** @var TwitterOAuth */
13
    protected $twitter;
14
15
    /**
16
     * @param TwitterOAuth $twitter
17
     */
18 3
    public function __construct(TwitterOAuth $twitter)
19
    {
20 3
        $this->twitter = $twitter;
21 3
    }
22
23
    /**
24
     * Send the given notification.
25
     *
26
     * @param mixed $notifiable
27
     * @param \Illuminate\Notifications\Notification $notification
28
     *
29
     * @throws CouldNotSendNotification
30
     */
31 3
    public function send($notifiable, Notification $notification)
32
    {
33 3
        if ($twitterSettings = $notifiable->routeNotificationFor('twitter')) {
34
            $this->switchSettings($twitterSettings);
35
        }
36
37 3
        $twitterMessage = $notification->toTwitter($notifiable);
0 ignored issues
show
Bug introduced by
The method toTwitter() 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...
38 3
        if (is_a($twitterMessage, TwitterStatusUpdate::class) && $twitterMessage->getImages()) {
39 1
            $this->twitter->setTimeouts(10, 15);
40
41 1
            $twitterMessage->imageIds = collect($twitterMessage->getImages())->map(function ($image) {
42 1
                $media = $this->twitter->upload('media/upload', ['media' => $image->getPath()]);
43
44 1
                return $media->media_id_string;
45 1
            });
46 1
        }
47
48 3
        $this->twitter->post($twitterMessage->getApiEndpoint(), $twitterMessage->getRequestBody());
49
50 3
        if ($this->twitter->getLastHttpCode() !== 200) {
51 1
            throw CouldNotSendNotification::serviceRespondedWithAnError($this->twitter->getLastBody());
52
        }
53 2
    }
54
55
    /**
56
     * Use per user settings instead of default ones
57
     * @param $twitterSettings
58
     */
59
    private function switchSettings($twitterSettings)
60
    {
61
        $this->twitter = new TwitterOAuth($twitterSettings[0], $twitterSettings[1], $twitterSettings[2],
62
            $twitterSettings[3]);
63
    }
64
65
}
66