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 ( dafe9f...dc72b4 )
by Dwight
10s
created

FacebookPosterPost   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 3
dl 0
loc 150
ccs 38
cts 38
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getContent() 0 4 1
A scheduledFor() 0 11 2
A withLink() 0 6 1
A withImage() 0 6 1
A withVideo() 0 14 3
A getApiEndpoint() 0 4 1
A getPostBody() 0 24 5
1
<?php
2
3
namespace NotificationChannels\FacebookPoster;
4
5
use DateTimeInterface;
6
use NotificationChannels\FacebookPoster\Attachments\Link;
7
use NotificationChannels\FacebookPoster\Attachments\Image;
8
use NotificationChannels\FacebookPoster\Attachments\Video;
9
10
class FacebookPosterPost
11
{
12
    /** @var string */
13
    protected $content;
14
15
    /** @object FacebookPosterLink */
16
    protected $link;
17
18
    /** @object FacebookPosterImage */
19
    protected $image;
20
21
    /** @object FacebookPosterVideo */
22
    protected $video;
23
24
    /** @var array */
25
    protected $params;
26
27
    /**
28
     * @var string
29
     */
30
    private $apiEndpoint = 'me/feed';
31
32 7
    public function __construct($postContent)
33
    {
34 7
        $this->content = $postContent;
35 7
    }
36
37
    /**
38
     * Get Post content.
39
     *
40
     * @return string
41
     */
42 7
    public function getContent()
43
    {
44 7
        return $this->content;
45
    }
46
47
    /**
48
     * Set facebook post main link.
49
     *
50
     * @param string $link
51
     *
52
     * @return $this
53
     */
54 1
    public function withLink($link)
55
    {
56 1
        $this->link = new Link($link);
57
58 1
        return $this;
59
    }
60
61
    /**
62
     * Set facebook post image.
63
     *
64
     * @param $imagePath
65
     * @param string $endpoint
66
     *
67
     * @return $this
68
     */
69 1
    public function withImage($imagePath, $endpoint = 'me/photos')
70
    {
71 1
        $this->image = new Image($imagePath, $endpoint);
72
73 1
        return $this;
74
    }
75
76
    /**
77
     * Set facebook post image.
78
     *
79
     * @param $videoPath
80
     * @param array  $data
81
     * @param string $endpoint
82
     *
83
     * @return $this
84
     */
85 1
    public function withVideo($videoPath, $data = [], $endpoint = 'me/videos')
86
    {
87 1
        $this->video = new video($videoPath, $endpoint);
88
89 1
        if (isset($data['title'])) {
90 1
            $this->video->setTitle($data['title']);
91
        }
92
93 1
        if (isset($data['description'])) {
94 1
            $this->video->setDescription($data['description']);
95
        }
96
97 1
        return $this;
98
    }
99
100
    /**
101
     * Schedule the post for a date in the future.
102
     *
103
     * @param string $timestamp UNIX timestamp
104
     *
105
     * @param  \DateTimeInterface|int  $timestamp
106
     * @return $this
107
     */
108 3
    public function scheduledFor($timestamp)
109
    {
110 3
        $timestamp = $timestamp instanceof DateTimeInterface
111 2
            ? $timestamp->getTimestamp()
112 3
            : $timestamp;
113
114 3
        $this->params['published'] = false;
115 3
        $this->params['scheduled_publish_time'] = $timestamp;
116
117 3
        return $this;
118
    }
119
120
    /**
121
     * Return Facebook Post api endpoint.
122
     *
123
     * @return string
124
     */
125 4
    public function getApiEndpoint()
126
    {
127 4
        return $this->apiEndpoint;
128
    }
129
130
    /**
131
     * Build Facebook post request body.
132
     *
133
     * @return array
134
     */
135 7
    public function getPostBody()
136
    {
137
        $body = [
138 7
            'message' => $this->getContent(),
139
        ];
140
141 7
        if ($this->link != null) {
142 1
            $body['link'] = $this->link->getUrl();
143
        }
144
145 7
        if ($this->image != null) {
146 1
            $body['media'] = $this->image;
147
        }
148
149 7
        if ($this->video != null) {
150 1
            $body['media'] = $this->video;
151
        }
152
153 7
        if ($this->params != null) {
154 3
            $body = array_merge($body, $this->params);
155
        }
156
157 7
        return $body;
158
    }
159
}
160