HeaderExtractor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAuthorizationHeader() 0 7 3
1
<?php declare(strict_types=1);
2
3
namespace Firesphere\GraphQLJWT\Helpers;
4
5
use SilverStripe\Control\HTTPRequest;
6
7
/**
8
 * Parent class can detect JWT tokens in a request
9
 */
10
trait HeaderExtractor
11
{
12
    /**
13
     * Get JWT from request, or null if not present
14
     *
15
     * @param HTTPRequest $request
16
     * @return string|null
17
     */
18
    protected function getAuthorizationHeader(HTTPRequest $request): ?string
19
    {
20
        $authHeader = $request->getHeader('Authorization');
21
        if ($authHeader && preg_match('/Bearer\s+(?<token>.*)$/i', $authHeader, $matches)) {
22
            return $matches['token'];
23
        }
24
        return null;
25
    }
26
}
27