Completed
Pull Request — master (#14)
by
unknown
01:13
created

Recurly::headers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Clarkeash\Shield\Services;
4
5
use Illuminate\Http\Request;
6
7
class Recurly extends BaseService
8
{
9
    public function verify(Request $request): bool
10
    {
11
        $processed = $this->process($this->header($request, 'Authorization'));
12
13
        $username = config('shield.services.recurly.username');
14
        $password = config('shield.services.recurly.password');
15
16
        return ($username===$processed[0] && $password===$processed[1]);
17
    }
18
19
    protected function process(string $header): array
20
    {
21
        list($token_type, $payload) = explode(" ", $header, 2);
22
      
23
        $data = array();
24
        if (strcasecmp($token_type, "Bearer") == 0) {
25
            $section = base64_decode($payload);
26
            $data = explode(':', $section);
27
        }
28
29
        return $data;
30
    }
31
32
    public function headers(): array
33
    {
34
        return ['Authorization'];
35
    }
36
}
37