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 ( 440f9f...c814ca )
by Freek
02:36
created

Response   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 110
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 6 1
A __construct() 0 10 1
A withText() 0 6 1
A onChannel() 0 6 1
A displayResponseToUserWhoTypedCommand() 0 6 1
A displayResponseToEveryoneOnChannel() 0 10 2
A send() 0 4 1
A getIlluminateResponse() 0 4 1
A getPayload() 0 13 1
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;
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
    }
34
35
    public function __construct(Client $client, Request $request)
36
    {
37
        $this->client = $client;
38
39
        $this->request = $request;
40
41
        $this->channel = $request->channelName;
42
43
        $this->displayResponseToUserWhoTypedCommand();
44
    }
45
46
    /**
47
     * @param string $text
48
     *
49
     * @return $this
50
     */
51
    public function withText(string $text)
52
    {
53
        $this->text = $text;
54
55
        return $this;
56
    }
57
58
    public function onChannel(string $channelName)
59
    {
60
        $this->channel = $channelName;
61
62
        return $this;
63
    }
64
65
    /**
66
     * @return $this
67
     */
68
    public function displayResponseToUserWhoTypedCommand()
69
    {
70
        $this->responseType = 'ephemeral';
71
72
        return $this;
73
    }
74
75
    /**
76
     * @param string $channelName
77
     *
78
     * @return $this
79
     */
80
    public function displayResponseToEveryoneOnChannel(string $channelName = '')
81
    {
82
        $this->responseType = 'in_channel';
83
84
        if ($channelName !== '') {
85
            $this->onChannel($channelName);
86
        }
87
88
        return $this;
89
    }
90
91
    /**
92
     * Send the response to Slack.
93
     */
94
    public function send()
95
    {
96
        $this->client->post($this->request->responseUrl, ['json' => $this->getPayload()]);
97
    }
98
99
    public function getIlluminateResponse(): IlluminateResponse
100
    {
101
        return new IlluminateResponse($this->getPayload());
102
    }
103
104
    protected function getPayload(): array
105
    {
106
        return [
107
            'text' => $this->text,
108
            'channel' => $this->channel,
109
            'link_names' => true,
110
            'unfurl_links' => true,
111
            'unfurl_media' => true,
112
            'mrkdwn' => true,
113
            'response_type' => $this->responseType,
114
            'attachments' => $this->attachments,
115
        ];
116
    }
117
}
118