DefaultSignatureValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 18 3
1
<?php
2
3
namespace Spatie\WebhookClient\SignatureValidator;
4
5
use Illuminate\Http\Request;
6
use Spatie\WebhookClient\Exceptions\WebhookFailed;
7
use Spatie\WebhookClient\WebhookConfig;
8
9
class DefaultSignatureValidator implements SignatureValidator
10
{
11
    public function isValid(Request $request, WebhookConfig $config): bool
12
    {
13
        $signature = $request->header($config->signatureHeaderName);
14
15
        if (! $signature) {
16
            return false;
17
        }
18
19
        $signingSecret = $config->signingSecret;
20
21
        if (empty($signingSecret)) {
22
            throw WebhookFailed::signingSecretNotSet();
23
        }
24
25
        $computedSignature = hash_hmac('sha256', $request->getContent(), $signingSecret);
26
27
        return hash_equals($signature, $computedSignature);
28
    }
29
}
30