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 ( cda627...6f7b29 )
by
unknown
85:30 queued 78:40
created

TwitterStatusUpdate   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 4
dl 0
loc 107
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A withImage() 0 8 1
A getContent() 0 4 1
A getImages() 0 4 1
A getApiEndpoint() 0 4 1
A getRequestBody() 0 12 2
A messageIsTooLong() 0 7 2
1
<?php
2
3
namespace NotificationChannels\Twitter;
4
5
use Kylewm\Brevity\Brevity;
6
use Illuminate\Support\Collection;
7
use NotificationChannels\Twitter\Exceptions\CouldNotSendNotification;
8
9
class TwitterStatusUpdate
10
{
11
    /** @var string */
12
    protected $content;
13
14
    /**
15
     * @var  array
16
     */
17
    private $images;
18
19
    /**
20
     * @var  Collection
21
     */
22
    public $imageIds;
23
24
    /**
25
     * @var  string
26
     */
27
    private $apiEndpoint = 'statuses/update';
28
29
    /*
30
     * @param  string $content
31
     */
32 10
    public function __construct($content)
33
    {
34 10
        if ($exceededLength = $this->messageIsTooLong($content, new Brevity())) {
35 2
            throw CouldNotSendNotification::statusUpdateTooLong($exceededLength);
36
        }
37
38 8
        $this->content = $content;
39 8
    }
40
41
    /**
42
     * Set Twitter media files.
43
     *
44
     * @param   array|string $images
45
     * @return  $this
46
     */
47
    public function withImage($images)
48
    {
49 3
        collect($images)->each(function ($image) {
50 3
            $this->images[] = new TwitterImage($image);
51 3
        });
52
53 3
        return $this;
54
    }
55
56
    /**
57
     * Get Twitter status update content.
58
     *
59
     * @return  string
60
     */
61 7
    public function getContent()
62
    {
63 7
        return $this->content;
64
    }
65
66
    /**
67
     * Get Twitter images list.
68
     *
69
     * @return  string
70
     */
71 6
    public function getImages()
72
    {
73 6
        return $this->images;
74
    }
75
76
    /**
77
     * Return Twitter status update api endpoint.
78
     * @return  string
79
     */
80 3
    public function getApiEndpoint()
81
    {
82 3
        return $this->apiEndpoint;
83
    }
84
85
    /**
86
     * Build Twitter request body.
87
     * @return  array
88
     */
89 4
    public function getRequestBody()
90
    {
91
        $body = [
92 4
            'status' => $this->getContent(),
93
        ];
94
95 4
        if ($this->imageIds) {
96 2
            $body['media_ids'] = $this->imageIds->implode(',');
97
        }
98
99 4
        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 10
    private function messageIsTooLong($content, Brevity $brevity)
109
    {
110 10
        $tweetLength = $brevity->tweetLength($content);
111 10
        $exceededLength = $tweetLength - 280;
112
113 10
        return $exceededLength > 0 ? $exceededLength : 0;
114
    }
115
}
116