Completed
Push — master ( ef0e27...1f22bd )
by Takashi
17s queued 12s
created

WebhookValidator::isValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Esa;
6
7
class WebhookValidator
8
{
9 5
    public function __construct(private ?string $secret)
10
    {
11 5
    }
12
13 5
    public function isValid(string $payload, string $signature): bool
14
    {
15 5
        $hash = hash_hmac('sha256', $payload, (string) $this->secret);
16
17 5
        return sprintf('sha256=%s', $hash) === $signature;
18
    }
19
}
20