GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

WebhookController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A verifySignature() 0 23 4
A __invoke() 0 8 1
1
<?php
2
3
namespace ProtoneMedia\LaravelPaddle\Http;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Arr;
7
use ProtoneMedia\LaravelPaddle\Events\Event;
8
9
class WebhookController
10
{
11
    /**
12
     * https://developer.paddle.com/webhook-reference/verifying-webhooks
13
     *
14
     * @param  string $encodedSignature
15
     * @param  array  $data
16
     * @return void
17
     *
18
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
19
     */
20
    private function verifySignature(string $encodedSignature = null, array $data)
21
    {
22
        ksort($data);
23
24
        foreach ($data as $key => $value) {
25
            if (in_array(gettype($value), ['object', 'array'])) {
26
                continue;
27
            }
28
29
            $data[$key] = "$value";
30
        }
31
32
        $verified = openssl_verify(
33
            serialize($data),
34
            base64_decode($encodedSignature),
35
            openssl_get_publickey(config('paddle.public_key')),
36
            OPENSSL_ALGO_SHA1
37
        );
38
39
        if ($verified !== 1) {
40
            abort(403);
41
        }
42
    }
43
44
    /**
45
     * Verify the request signature and fire the event.
46
     *
47
     * @param  \Illuminate\Http\Request $request
48
     * @return void
49
     */
50
    public function __invoke(Request $request)
51
    {
52
        $data = Arr::except($request->all(), $signatureKey = 'p_signature');
53
54
        $this->verifySignature($request->input($signatureKey), $data);
55
56
        Event::fire($data, $request);
57
    }
58
}
59