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 ( e31889...c11a4c )
by Freek
03:13
created

SlashCommandResponse::getPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Spatie\SlashCommand;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Http\Response;
7
8
class SlashCommandResponse
9
{
10
    /** @var \Spatie\SlashCommand\SlashCommandData */
11
    protected $slashCommandData;
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(SlashCommandData $slashCommandData): SlashCommandResponse
29
    {
30
        $client = app(Client::class);
31
32
        return (new static($client, $slashCommandData))
33
            ->displayResponseOnlyToUserWhoTypedCommand();
34
    }
35
36
    public function __construct(Client $client, SlashCommandData $slashCommandData)
37
    {
38
        $this->client = $client;
39
40
        $this->slashCommandData = $slashCommandData;
41
42
        $this->channel = $slashCommandData->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 displayResponseOnlyToUserWhoTypedCommand()
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->slashCommandData->responseUrl, ['json' => $this->getPayload()]);
90
    }
91
92
    /*
93
     * Get the http response
94
     */
95
    public function getHttpResponse(): Response
96
    {
97
        return new Response($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