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

WebhookValidator::isValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

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
rs 10
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