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

FacebookPosterChannel   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 71
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B send() 0 27 3
A guardAgainstInvalidPostContent() 0 16 4
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