Completed
Push — master ( d51485...4815df )
by yoshihiro
01:33
created

AuthorizationHeaderTokenExtractor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 18
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 10 3
A extract() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Piotzkhider\FirebaseAuthenticationModule\Extractor;
6
7
use Aura\Web\Request;
8
use Koriym\HttpConstants\RequestHeader;
9
10
class AuthorizationHeaderTokenExtractor implements TokenExtractorInterface
11
{
12 1
    public function supports(Request $request): bool
13
    {
14 1
        if (null === $header = $request->headers->get(RequestHeader::AUTHORIZATION)) {
15
            return false;
16
        }
17
18 1
        $parts = explode(' ', $header);
19
20 1
        return count($parts) === 2 && strcasecmp($parts[0], 'Bearer') === 0;
21
    }
22
23 1
    public function extract(Request $request): string
24
    {
25 1
        return str_ireplace('Bearer ', '', $request->headers->get(RequestHeader::AUTHORIZATION));
26
    }
27
}
28