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 (#32)
by Dwight
03:14
created

FacebookPosterPost::withVideo()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 7
cp 0
rs 9.7998
c 0
b 0
f 0
cc 3
nc 4
nop 3
crap 12
1
<?php
2
3
namespace NotificationChannels\FacebookPoster;
4
5
use DateTime;
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 2
    public function __construct($postContent)
33
    {
34 2
        $this->content = $postContent;
35 2
    }
36
37
    /**
38
     * Get Post content.
39
     *
40
     * @return string
41
     */
42 2
    public function getContent()
43
    {
44 2
        return $this->content;
45
    }
46
47
    /**
48
     * Set facebook post main link.
49
     *
50
     * @param string $link
51
     *
52
     * @return $this
53
     */
54
    public function withLink($link)
55
    {
56
        $this->link = new Link($link);
57
58
        return $this;
59
    }
60
61
    /**
62
     * Set facebook post image.
63
     *
64
     * @param $imagePath
65
     * @param string $endpoint
66
     *
67
     * @return $this
68
     */
69
    public function withImage($imagePath, $endpoint = 'me/photos')
70
    {
71
        $this->image = new Image($imagePath, $endpoint);
72
73
        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
    public function withVideo($videoPath, $data = [], $endpoint = 'me/videos')
86
    {
87
        $this->video = new video($videoPath, $endpoint);
88
89
        if (isset($data['title'])) {
90
            $this->video->setTitle($data['title']);
91
        }
92
93
        if (isset($data['description'])) {
94
            $this->video->setDescription($data['description']);
95
        }
96
97
        return $this;
98
    }
99
100
    /**
101
     * Schedule the post for a date in the future.
102
     *
103
     * @param string $timestamp UNIX timestamp
104
     *
105
     * @return $this
106
     */
107 2
    public function scheduledFor($timestamp)
108
    {
109 2
        $timestamp = $timestamp instanceof DateTime
110 1
            ? $timestamp->getTimestamp()
111 2
            : $timestamp;
112
113 2
        $this->params['published'] = false;
114 2
        $this->params['scheduled_publish_time'] = $timestamp;
115
116 2
        return $this;
117
    }
118
119
    /**
120
     * Return Facebook Post api endpoint.
121
     *
122
     * @return string
123
     */
124
    public function getApiEndpoint()
125
    {
126
        return $this->apiEndpoint;
127
    }
128
129
    /**
130
     * Build Facebook post request body.
131
     *
132
     * @return array
133
     */
134 2
    public function getPostBody()
135
    {
136
        $body = [
137 2
            'message' => $this->getContent(),
138
        ];
139
140 2
        if ($this->link != null) {
141
            $body['link'] = $this->link->getUrl();
142
        }
143
144 2
        if ($this->image != null) {
145
            $body['media'] = $this->image;
146
        }
147
148 2
        if ($this->video != null) {
149
            $body['media'] = $this->video;
150
        }
151
152 2
        if ($this->params != null) {
153 2
            $body = array_merge($body, $this->params);
154
        }
155
156 2
        return $body;
157
    }
158
}
159