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 ( 3c5f28...9ed616 )
by
unknown
02:43
created

guardAgainstInvalidPostContent()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 1
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
    public function __construct(Facebook $facebook)
19
    {
20
        $this->facebook = $facebook;
21
    }
22
23
    /**
24
     * Send the given notification.
25
     *
26
     * @param mixed                                  $notifiable
27
     * @param \Illuminate\Notifications\Notification $notification
28
     *
29
     * @throws InvalidPostContentException
30
     */
31
    public function send($notifiable, Notification $notification)
32
    {
33
        $facebookMessage = $notification->toFacebookPoster($notifiable);
0 ignored issues
show
Bug introduced by
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...
34
35
        $postBody = $facebookMessage->getPostBody();
36
37
        $endpoint = $facebookMessage->getApiEndpoint();
38
39
        $this->guardAgainstInvalidPostContent($postBody);
40
41
        // here we check if post body has image or video to upload it first to facebook
42
        if (isset($postBody['media'])) {
43
            $endpoint = $postBody['media']->getApiEndpoint();
44
45
            if ($postBody['media'] instanceof Video) {
46
                $postBody = array_merge($postBody, $postBody['media']->getData());
47
            }
48
49
            $method = $postBody['media']->getMethod();
50
51
            $postBody['source'] = $this->facebook->{$method}($postBody['media']->getPath());
52
53
            unset($postBody['media']);
54
        }
55
56
        $this->facebook->post($endpoint, $postBody);
57
    }
58
59
    /**
60
     * @param array $postBody
61
     *
62
     * @throws \NotificationChannels\FacebookPoster\Exceptions\InvalidPostContent
63
     */
64
    protected function guardAgainstInvalidPostContent($postBody)
65
    {
66
        if (! is_null($postBody['message'])) {
67
            return;
68
        }
69
70
        if (isset($postBody['link'])) {
71
            return;
72
        }
73
74
        if (isset($postBody['media'])) {
75
            return;
76
        }
77
78
        throw InvalidPostContent::noContentSet();
79
    }
80
}
81