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
Pull Request — master (#31)
by
unknown
08:56
created

FacebookPosterPost   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 145
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 3
dl 0
loc 145
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0

8 Methods

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