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 ( 94f263...4f7e56 )
by Freek
02:01
created

SlashCommandResponse::finalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 19
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace Spatie\SlashCommand;
4
5
use Illuminate\Http\Request;
6
use \Symfony\Component\HttpFoundation\Response;
7
8
class SlashCommandResponse extends Response
9
{
10
    /** @var SlashCommandRequest */
11
    protected $request;
12
13
    /** @var string */
14
    protected $text;
15
16
    /** @var string */
17
    protected $responseType = 'ephemeral';
18
19
    /** @var string */
20
    protected $attachments = '';
21
22
    public static function createForRequest(Request $request)
23
    {
24
        return (new static())
25
            ->setRequest($request)
26
            ->displayResponseOnlyToUserWhoTypedCommand();
27
    }
28
29
    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...
30
    {
31
        $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...
32
33
        return $this;
34
    }
35
36
    public function setText(string $text)
37
    {
38
        $this->text = $text;
39
40
        return $this;
41
    }
42
43
    public function displayResponseOnlyToUserWhoTypedCommand()
44
    {
45
        $this->responseType = 'ephemeral';
46
47
        return $this;
48
    }
49
50
    public function displayResponseToEveryoneOnChannel()
51
    {
52
        $this->responseType = 'in_channel';
53
54
        return $this;
55
    }
56
57
    /**
58
     * Prepares the payload to be sent to the response.
59
     */
60
    public function finalize()
61
    {
62
        $payload = [
63
            'text' => $this->text,
64
            'link_names' => true,
65
            'unfurl_links' => true,
66
            'unfurl_media' => true,
67
            'mrkdwn' => true,
68
            'response_type' => $this->responseType,
69
        ];
70
71
        $payload['attachments'] = $this->attachments;
72
73
        $this->headers->set('Content-Type', 'application/json');
74
75
        $this->setContent(json_encode($payload));
76
77
        return $this;
78
    }
79
}
80