Authenticatable::authenticate()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 4
nc 2
nop 2
1
<?php
2
3
namespace Picqer\Financials\Exact\Webhook;
4
5
trait Authenticatable
6
{
7
    public function authenticate($requestContent, $webhookSecret)
8
    {
9
        $matches = [];
10
        $matched = preg_match('/^{"Content":(.*),"HashCode":"(.*)"}$/', $requestContent, $matches);
11
12
        if ($matched === 1 && isset($matches[1]) && isset($matches[2])) {
13
            return $matches[2] === strtoupper(hash_hmac('sha256', $matches[1], $webhookSecret));
14
        }
15
16
        return false;
17
    }
18
}
19