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

SlackCommandResponder::getResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Spatie\SlashCommand;
4
5
6
use Illuminate\Http\Request;
7
use Spatie\SlashCommand\SlashCommandHandler\BaseHandler;
8
9
class SlackCommandResponder
10
{
11
    /**
12
     * @var array
13
     */
14
    private $commandConfig;
15
    /**
16
     * @var Request
17
     */
18
    private $request;
19
20
    public function __construct(array $commandConfig, 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...
21
    {
22
        $this->commandConfig = $commandConfig;
23
24
        $this->request = $request;
25
    }
26
27
    public function getResponse() {
28
29
        $this->guardAgainstInvalidRequest();
30
31
        $handler = $this->determineResponseHandler();
32
33
        $response = $handler->handleCurrentRequest();
34
35
        return $response->finalize();
36
    }
37
38
    protected function guardAgainstInvalidRequest()
39
    {
40
        if (!request()->has('token')) {
41
            throw InvalidSlashCommandRequest::tokenNotFound();
42
        }
43
44
        if (request()->get('token') != $this->commandConfig['verification_token']) {
45
            throw InvalidSlashCommandRequest::invalidToken(request()->get('token'));
46
        }
47
    }
48
49
    /**
50
     * @return mixed
51
     */
52
    protected function determineResponseHandler()
53
    {
54
        $handler = collect($this->commandConfig['handlers'])
55
            ->map(function (string $handlerClassName) {
56
                return new $handlerClassName(request());
57
            })
58
            ->filter(function (BaseHandler $handler) {
59
                return $handler->canHandleCurrentRequest();
60
            })->first();
61
62
        if (!$handler) {
63
            throw RequestCouldNotBeProcessed::noHandlerFound(request());
64
        }
65
        return $handler;
66
    }
67
}