Passed
Pull Request — master (#15)
by Takashi
05:35
created

WebhookValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 11
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A isValid() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Esa;
6
7
class WebhookValidator
8
{
9
    public function __construct(private ?string $secret)
10
    {
11
    }
12
13
    public function isValid(string $payload, string $signature): bool
14
    {
15
        $hash = hash_hmac('sha256', $payload, (string) $this->secret);
16
17
        return sprintf('sha256=%s', $hash) === $signature;
18
    }
19
}
20