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 ( 9ca3c4...0e5848 )
by Freek
02:03
created

Response::send()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\SlashCommand;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Http\Response as IlluminateResponse;
7
8
class Response
9
{
10
    /** @var \Spatie\SlashCommand\Request */
11
    protected $request;
12
13
    /** @var string */
14
    protected $text;
15
16
    /** @var string */
17
    protected $responseType = 'ephemeral';
18
19
    /** @var string */
20
    protected $channel;
21
22
    /** @var string */
23
    protected $attachments = '';
24
25
    /** @var \GuzzleHttp\Client */
26
    protected $client;
27
28
    public static function create(Request $request): Response
29
    {
30
        $client = app(Client::class);
31
32
        return (new static($client, $request))
33
            ->displayResponseToUserWhoTypedCommand();
34
    }
35
36
    public function __construct(Client $client, Request $request)
37
    {
38
        $this->client = $client;
39
40
        $this->request = $request;
41
42
        $this->channel = $request->channelName;
43
    }
44
45
    /**
46
     * @param string $text
47
     *
48
     * @return $this
49
     */
50
    public function setText(string $text)
51
    {
52
        $this->text = $text;
53
54
        return $this;
55
    }
56
57
    public function onChannel(string $channelName)
58
    {
59
        $this->channel = $channelName;
60
61
        return $this;
62
    }
63
64
    /**
65
     * @return $this
66
     */
67
    public function displayResponseToUserWhoTypedCommand()
68
    {
69
        $this->responseType = 'ephemeral';
70
71
        return $this;
72
    }
73
74
    /**
75
     * @return $this
76
     */
77
    public function displayResponseToEveryoneOnChannel()
78
    {
79
        $this->responseType = 'in_channel';
80
81
        return $this;
82
    }
83
84
    /**
85
     * Send the response to Slack.
86
     */
87
    public function send()
88
    {
89
        $this->client->post($this->request->responseUrl, ['json' => $this->getPayload()]);
90
    }
91
92
    /*
93
     * Get the http response
94
     */
95
    public function getIlluminateResponse(): IlluminateResponse
96
    {
97
        return new IlluminateResponse($this->getPayload());
98
    }
99
100
    protected function getPayload(): array
101
    {
102
        return [
103
            'text' => $this->text,
104
            'channel' => $this->channel,
105
            'link_names' => true,
106
            'unfurl_links' => true,
107
            'unfurl_media' => true,
108
            'mrkdwn' => true,
109
            'response_type' => $this->responseType,
110
            'attachments' => $this->attachments,
111
        ];
112
    }
113
}
114