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 ( 474d0a...9d0de3 )
by Dwight
05:42
created

FacebookPosterPost::validate()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 4.25

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 10
c 0
b 0
f 0
cc 4
nc 2
nop 0
crap 4.25
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
use NotificationChannels\FacebookPoster\Exceptions\InvalidPostContent;
10
11
class FacebookPosterPost
12
{
13
    /**
14
     * The post message.
15
     *
16
     * @var string
17
     */
18
    protected $message;
19
20
    /**
21
     * The post link.
22
     *
23
     * @var string
24
     */
25
    protected $link;
26
27
    /**
28
     * The post image.
29
     *
30
     * @var \NotificationChannels\FacebookPoster\Attachments\Image
31
     */
32
    protected $image;
33
34
    /**
35
     * The post video.
36
     *
37
     * @var \NotificationChannels\FacebookPoster\Attachments\Video
38
     */
39
    protected $video;
40
41
    /**
42
     * The post API endpoint.
43
     *
44
     * @var string
45
     */
46
    protected $apiEndpoint = 'me/feed';
47
48
    /**
49
     * Create a new post instance.
50
     *
51
     * @param  string  $message
52
     * @return void
53
     */
54
    public function __construct($message)
55
    {
56
        $this->message = $message;
57
    }
58
59
    /**
60
     * Get post message.
61 7
     *
62
     * @return string
63 7
     */
64 7
    public function getMessage()
65
    {
66
        return $this->message;
67
    }
68
69
    /**
70
     * Set facebook post main link.
71 7
     *
72
     * @param string $link
73 7
     *
74
     * @return $this
75
     */
76
    public function withLink($link)
77
    {
78
        $this->link = $link;
79
80
        return $this;
81
    }
82
83 1
    /**
84
     * Set a post image.
85 1
     *
86
     * @param  string  $path
87 1
     * @param  string  $endpoint
88
     * @return $this
89
     */
90
    public function withImage($path, $endpoint = 'me/photos')
91
    {
92
        $this->image = new Image($path, $endpoint);
93
94
        return $this;
95
    }
96
97 1
    /**
98
     * Set a post video.
99 1
     *
100
     * @param  string  $path
101 1
     * @param  string  $title
102
     * @param  string  $description
103
     * @param  string  $endpoint
104
     * @return $this
105
     */
106
    public function withVideo($path, $title = null, $description = null, $endpoint = 'me/videos')
107
    {
108
        $this->video = new Video($path, $title, $description, $endpoint);
109
110
        return $this;
111
    }
112
113 1
    /**
114
     * Schedule the post for a date in the future.
115 1
     *
116
     * @param  \DateTimeInterface|int  $timestamp
117 1
     * @return $this
118
     */
119
    public function scheduledFor($timestamp)
120
    {
121
        $timestamp = $timestamp instanceof DateTimeInterface
122
            ? $timestamp->getTimestamp()
123
            : $timestamp;
124
125
        $this->published = false;
126 3
        $t
127
        $this->params['published'] = false;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_VARIABLE
Loading history...
128 3
        $this->params['scheduled_publish_time'] = $timestamp;
129 2
130 3
        return $this;
131
    }
132 3
133 3
    /**
134
     * Return Facebook Post api endpoint.
135 3
     *
136
     * @return string
137
     */
138
    public function getApiEndpoint()
139
    {
140
        return $this->apiEndpoint;
141
    }
142
143 4
    public function getMedia()
144
    {
145 4
        return $this->image ?: $this->video;
146
    }
147
148
    /**
149
     * Build Facebook post request body.
150
     *
151
     * @return array
152
     */
153 7
    public function getContent()
154
    {
155 7
        $this->validate();
156
157
        $body = [
158 7
            'message' => $this->getMessage(),
159
        ];
160
161 7
        if ($this->link != null) {
162 1
            $body['link'] = $this->link;
163
        }
164
165 7
        if ($this->params != null) {
166 1
            $body = array_merge($body, $this->params);
167
        }
168
169 7
        return $body;
170 1
    }
171
172
    /**
173 7
     * Validate that there is acceptable post content.
174 3
     *
175
     * @throws \NotificationChannels\FacebookPoster\Exceptions\InvalidPostContent
176
     */
177 7
    protected function validate()
178
    {
179
        if ($this->message || $this->link || $this->media) {
180
            return;
181
        }
182
183
        throw InvalidPostContent::noContentSet();
184
    }
185
}
186