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 ( 897a16...8dd544 )
by Dwight
18s queued 11s
created

FacebookPosterChannel   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 68.97%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 81
ccs 20
cts 29
cp 0.6897
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 28 3
A guardAgainstInvalidPostContent() 0 16 4
A switchSettings() 0 4 1
1
<?php
2
3
namespace NotificationChannels\FacebookPoster;
4
5
use Facebook\Facebook;
6
use Illuminate\Notifications\Notification;
7
use NotificationChannels\FacebookPoster\Exceptions\InvalidPostContent;
8
9
class FacebookPosterChannel
10
{
11
    /** @var \Facebook\Facebook */
12
    protected $facebook;
13
14
    /**
15
     * @param \Facebook\Facebook $facebook
16
     */
17 4
    public function __construct(Facebook $facebook)
18
    {
19 4
        $this->facebook = $facebook;
20 4
    }
21
22
    /**
23
     * Send the given notification.
24
     *
25
     * @param mixed                                  $notifiable
26
     * @param \Illuminate\Notifications\Notification $notification
27
     *
28
     * @throws InvalidPostContentException
29
     */
30 4
    public function send($notifiable, Notification $notification)
31
    {
32 4
        if ($facebookSettings = $notifiable->routeNotificationFor('facebookPoster')) {
33
            $this->switchSettings($facebookSettings);
34
        }
35
36 4
        $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...
37
38 4
        $postBody = $facebookMessage->getPostBody();
39
40 4
        $endpoint = $facebookMessage->getApiEndpoint();
41
42 4
        $this->guardAgainstInvalidPostContent($postBody);
43
44 4
        if (isset($postBody['media'])) {
45 2
            $endpoint = $postBody['media']->getApiEndpoint();
46
47 2
            $postBody = array_merge($postBody, $postBody['media']->getData());
48
49 2
            $method = $postBody['media']->getApiMethod();
50
51 2
            $postBody['source'] = $this->facebook->{$method}($postBody['media']->getPath());
52
53 2
            unset($postBody['media']);
54
        }
55
56 4
        $this->facebook->post($endpoint, $postBody);
57 4
    }
58
59
    /**
60
     * @param array $postBody
61
     *
62
     * @throws \NotificationChannels\FacebookPoster\Exceptions\InvalidPostContent
63
     */
64 4
    protected function guardAgainstInvalidPostContent($postBody)
65
    {
66 4
        if (! is_null($postBody['message'])) {
67 4
            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
    /**
82
     * Use per user settings instead of default ones.
83
     * @param $facebookSettings
84
     */
85
    private function switchSettings($facebookSettings)
86
    {
87
        $this->facebook = new Facebook($facebookSettings);
88
    }
89
}
90