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 ( b1c59c...16d2fd )
by
unknown
9s
created

TwitterStatusUpdate::messageIsTooLong()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 6
1
<?php
2
3
namespace NotificationChannels\Twitter;
4
5
use Kylewm\Brevity\Brevity;
6
use NotificationChannels\Twitter\Exceptions\CouldNotSendNotification;
7
use NotificationChannels\Twitter\TwitterImage;
8
9
class TwitterStatusUpdate
10
{
11
12
    /** @var string */
13
    protected $content;
14
15
    /**
16
     * @var  array
17
     */
18
    private $images;
19
20
    /**
21
     * @var  array
22
     */
23
    public $imageIds;
24
25
    /**
26
     * @var  string
27
     */
28 7
    private $apiEndpoint = 'statuses/update';
29
30 7
    /*
31 7
     * @param  string $content
32 7
     */
33
    public function __construct($content)
34
    {
35
        if ($exceededLength = $this->messageIsTooLong($content, new Brevity())) {
36
            throw CouldNotSendNotification::statusUpdateTooLong($exceededLength);
37
        }
38
        $this->content = $content;
39 6
    }
40
41 6
    /**
42
     * Set Twitter media files.
43
     *
44
     * @param   array|string $images
45
     * @return  $this
46
     */
47
    public function withImage($images)
48
    {
49 5
        collect($images)->each(function ($image) {
50
            $this->images[] = new TwitterImage($image);
51 5
        });
52
53
        return $this;
54
    }
55
56
    /**
57
     * Get Twitter status update content.
58 3
     *
59
     * @return  string
60 3
     */
61
    public function getContent()
62
    {
63
        return $this->content;
64
    }
65
66
    /**
67 4
     * Get Twitter images list.
68
     *
69
     * @return  string
70 4
     */
71 4
    public function getImages()
72
    {
73 4
        return $this->images;
74 2
    }
75 2
76
    /**
77 4
     * Return Twitter status update api endpoint.
78
     * @return  string
79
     */
80
    public function getApiEndpoint()
81
    {
82
        return $this->apiEndpoint;
83
    }
84
85
    /**
86
     * Build Twitter request body.
87
     * @return  array
88
     */
89
    public function getRequestBody()
90
    {
91
        $body = [
92
            'status' => $this->getContent(),
93
        ];
94
95
        if ($this->imageIds) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->imageIds of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
96
            $body['media_ids'] = $this->imageIds->implode(',');
0 ignored issues
show
Bug introduced by
The method implode cannot be called on $this->imageIds (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
97
        }
98
99
        return $body;
100
    }
101
102
    /**
103
     * Check if the message length is too long
104
     * @param $content
105
     * @param $brevity
106
     * @return int
107
     */
108
    private function messageIsTooLong($content, $brevity)
109
    {
110
        $tweetLength = $brevity->tweetLength($content);
111
        $exceededLength = $tweetLength - 140;
112
113
        return $exceededLength > 0 ? $exceededLength : 0;
114
    }
115
}
116