Passed
Push — master ( ef2110...bce164 )
by Takashi
02:34
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 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Ttskch\Esa;
4
5
class WebhookValidator
6
{
7
    /**
8
     * @var string
9
     */
10
    private $secret;
11
12 5
    public function __construct($secret)
13
    {
14 5
        $this->secret = $secret;
15 5
    }
16
17
    /**
18
     * @param string $payload
19
     * @param string $signature
20
     * @return bool
21
     */
22 5
    public function isValid($payload, $signature)
23
    {
24 5
        $hash = hash_hmac('sha256', $payload, $this->secret);
25
26 5
        return sprintf('sha256=%s', $hash) === $signature;
27
    }
28
}
29