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
Push — master ( 8d291e...a8c3f8 )
by Dwight
03:11 queued 01:05
created

src/FacebookPosterChannel.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace NotificationChannels\FacebookPoster;
4
5
use Facebook\Facebook;
6
use Illuminate\Notifications\Notification;
7
use NotificationChannels\FacebookPoster\Attachments\Video;
8
use NotificationChannels\FacebookPoster\Exceptions\InvalidPostContent;
9
10
class FacebookPosterChannel
11
{
12
    /** @var \Facebook\Facebook */
13
    protected $facebook;
14
15
    /**
16
     * @param \Facebook\Facebook $facebook
17
     */
18 4
    public function __construct(Facebook $facebook)
19
    {
20 4
        $this->facebook = $facebook;
21 4
    }
22
23
    /**
24
     * Send the given notification.
25
     *
26
     * @param mixed                                  $notifiable
27
     * @param \Illuminate\Notifications\Notification $notification
28
     *
29
     * @throws InvalidPostContentException
30
     */
31 4
    public function send($notifiable, Notification $notification)
32
    {
33 4
        if ($facebookSettings = $notifiable->routeNotificationFor('facebookPoster')) {
34
            $this->switchSettings($facebookSettings);
35
        }
36
37 4
        $facebookMessage = $notification->toFacebookPoster($notifiable);
0 ignored issues
show
The method toFacebookPoster() 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
39 4
        $postBody = $facebookMessage->getPostBody();
40
41 4
        $endpoint = $facebookMessage->getApiEndpoint();
42
43 4
        $this->guardAgainstInvalidPostContent($postBody);
44
45
        // here we check if post body has image or video to upload it first to facebook
46 4
        if (isset($postBody['media'])) {
47 2
            $endpoint = $postBody['media']->getApiEndpoint();
48
49 2
            if ($postBody['media'] instanceof Video) {
50 1
                $postBody = array_merge($postBody, $postBody['media']->getData());
51
            }
52
53 2
            $method = $postBody['media']->getMethod();
54
55 2
            $postBody['source'] = $this->facebook->{$method}($postBody['media']->getPath());
56
57 2
            unset($postBody['media']);
58
        }
59
60 4
        $this->facebook->post($endpoint, $postBody);
61 4
    }
62
63
    /**
64
     * @param array $postBody
65
     *
66
     * @throws \NotificationChannels\FacebookPoster\Exceptions\InvalidPostContent
67
     */
68 4
    protected function guardAgainstInvalidPostContent($postBody)
69
    {
70 4
        if (! is_null($postBody['message'])) {
71 4
            return;
72
        }
73
74
        if (isset($postBody['link'])) {
75
            return;
76
        }
77
78
        if (isset($postBody['media'])) {
79
            return;
80
        }
81
82
        throw InvalidPostContent::noContentSet();
83
    }
84
85
    /**
86
     * Use per user settings instead of default ones.
87
     * @param $facebookSettings
88
     */
89
    private function switchSettings($facebookSettings)
90
    {
91
        $this->facebook = new Facebook($facebookSettings);
92
    }
93
}
94