Webhook::handle()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 7
c 2
b 1
f 0
dl 0
loc 13
rs 10
cc 3
nc 4
nop 2
1
<?php
2
3
namespace Lyal\Checkr\Laravel\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Log;
7
use Lyal\Checkr\Laravel\Facades\Checkr;
8
9
class Webhook
10
{
11
    public function handle($request, Closure $next)
12
    {
13
        if (stripos($request->header('User-Agent'), 'Checkr-Webhook') === false) {
14
            Log::alert('Invalid user agent for Checkr webhook');
15
            abort(404);
0 ignored issues
show
Bug introduced by
The function abort was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
            /** @scrutinizer ignore-call */ 
16
            abort(404);
Loading history...
16
        }
17
18
        if (hash_hmac('SHA256', $request->getContent(), Checkr::getKey()) !== $request->header('X-Checkr-Signature')) {
0 ignored issues
show
Bug introduced by
The method getKey() does not exist on Lyal\Checkr\Laravel\Facades\Checkr. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        if (hash_hmac('SHA256', $request->getContent(), Checkr::/** @scrutinizer ignore-call */ getKey()) !== $request->header('X-Checkr-Signature')) {
Loading history...
19
            Log::alert('Checkr signature does not match request.');
20
            abort(404);
21
        }
22
23
        return $next($request);
24
    }
25
}
26