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 ( c4effd...5428db )
by Freek
03:22
created

guardAgainstInvalidRequest()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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