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.

VerifySignature   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
eloc 15
c 2
b 2
f 0
dl 0
loc 29
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 3
A isValid() 0 12 2
1
<?php
2
3
namespace Multicoin\Api\Http\Middlewares;
4
5
use Closure;
6
use Multicoin\Api\Exceptions\WebhookFailed;
7
8
class VerifySignature
9
{
10
    public function handle($request, Closure $next)
11
    {
12
        $signature = $request->header('X-Multicoin-Signature');
13
14
        if (! $signature) {
15
            throw WebhookFailed::missingSignature();
16
        }
17
18
        if (! $this->isValid($signature, $request)) {
19
            throw WebhookFailed::invalidSignature($signature);
20
        }
21
22
        return $next($request);
23
    }
24
25
    protected function isValid(string $signature, $request): bool
26
    {
27
        $payload = $request->getContent();
0 ignored issues
show
Unused Code introduced by
The assignment to $payload is dead and can be removed.
Loading history...
28
        $secret = config('multicoin.api_key');
29
        if (empty($secret)) {
30
            throw WebhookFailed::signingSecretNotSet();
31
        }
32
        $timestamp = $request->header('timestamp');
33
        $token = $request->header('token');
34
        $computedSignature = hash_hmac('sha256', $token.$timestamp, $secret);
35
36
        return hash_equals($signature, $computedSignature);
37
    }
38
}
39