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 ( e3baf8...055b1c )
by Freek
03:22
created

SlashCommandResponse::setText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Spatie\SlashCommand;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Http\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class SlashCommandResponse extends Response
10
{
11
    /** @var SlashCommandRequest */
12
    protected $request;
13
14
    /** @var string */
15
    protected $text;
16
17
    /** @var string */
18
    protected $responseType = 'ephemeral';
19
20
    /** @var string */
21
    protected $attachments = '';
22
    
23
    /** @var \GuzzleHttp\Client  */
24
    protected  $client;
25
26
    public static function createForRequest(Request $request)
27
    {
28
        return app(SlashCommandResponse::class)
29
            ->setRequest($request)
30
            ->displayResponseOnlyToUserWhoTypedCommand();
31
    }
32
33
    public function __construct(Client $client)
34
    {
35
        $this->client = $client;
36
    }
37
38
    /**
39
     * @param \Illuminate\Http\Request $request
40
     * @return $this
41
     */
42
    public function setRequest(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
43
    {
44
        $this->responseType = $request;
0 ignored issues
show
Documentation Bug introduced by
It seems like $request of type object<Illuminate\Http\Request> is incompatible with the declared type string of property $responseType.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
46
        return $this;
47
    }
48
49
    public function getResponseUrl()
50
    {
51
        return $this->request->get('response_url');
52
    }
53
54
    /**
55
     * @param string $text
56
     * @return $this
57
     */
58
    public function setText(string $text)
59
    {
60
        $this->text = $text;
61
62
        return $this;
63
    }
64
65
    /**
66
     * @return $this
67
     */
68
    public function displayResponseOnlyToUserWhoTypedCommand()
69
    {
70
        $this->responseType = 'ephemeral';
71
72
        return $this;
73
    }
74
75
    /**
76
     * @return $this
77
     */
78
    public function displayResponseToEveryoneOnChannel()
79
    {
80
        $this->responseType = 'in_channel';
81
82
        return $this;
83
    }
84
85
    /**
86
     * Send the response to Slack
87
     */
88
    public function send()
89
    {
90
        $this->client->post($this->getResponseUrl(), ['json' => $this->getPayload()]);
91
    }
92
93
    /**
94
     * @return $this
95
     */
96
    public function finalize()
97
    {
98
        $this->headers->set('Content-Type', 'application/json');
99
100
        $this->setContent(json_encode($this->getPayload()));
101
102
        return $this;
103
    }
104
105
    protected function getPayload(): array
106
    {
107
        return [
108
            'text' => $this->text,
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