Completed
Push — master ( 381557...d947b3 )
by Ashley
01:11
created

Stripe   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 37
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 15 3
A process() 0 13 2
A headers() 0 4 1
1
<?php
2
3
namespace Clarkeash\Shield\Services;
4
5
use Clarkeash\Shield\Contracts\Service;
6
use Illuminate\Http\Request;
7
8
class Stripe implements Service
9
{
10
    public function verify(Request $request): bool
11
    {
12
        $processed = $this->process($request->header('Stripe-Signature'));
0 ignored issues
show
Bug introduced by
It seems like $request->header('Stripe-Signature') targeting Illuminate\Http\Concerns...actsWithInput::header() can also be of type array; however, Clarkeash\Shield\Services\Stripe::process() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
13
14
        $tolerance = config('shield.services.stripe.tolerance', 60 * 5);
15
16
        if(($tolerance > 0) && ((time() - $processed['t']) > $tolerance)) {
17
            return false;
18
        }
19
20
        $payload = $processed['t'] . '.' . $request->getContent();
21
        $generated = hash_hmac('sha256', $payload, config('shield.services.stripe.token'));
22
23
        return hash_equals($generated, $processed['v1']);
24
    }
25
26
    protected function process(string $header)
27
    {
28
        $sections = explode(',', $header);
29
30
        $data = [];
31
32
        foreach ($sections as $section) {
33
            $parts = explode('=', $section);
34
            $data[$parts[0]] = $parts[1];
35
        }
36
37
        return $data;
38
    }
39
40
    public function headers(): array
41
    {
42
        return ['Stripe-Signature'];
43
    }
44
}
45