AuthorizationHeaderTokenExtractor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 37
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A extract() 0 10 2
1
<?php
2
3
/**
4
 * This file is part of the BEAR.JwtAuthModule package.
5
 *
6
 * @license http://opensource.org/licenses/MIT MIT
7
 */
8
namespace BEAR\JwtAuth\Extractor;
9
10
use Aura\Web\Request;
11
use BEAR\JwtAuth\Annotation\Header;
12
13
class AuthorizationHeaderTokenExtractor implements TokenExtractorInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $header;
19
20
    /**
21
     * @var string
22
     */
23
    private $regexp;
24
25
    /**
26
     * @var Request
27
     */
28
    private $request;
29
30
    /**
31
     * @Header("header")
32
     */
33 3
    public function __construct(array $header, Request $request)
34
    {
35 3
        list($this->header, $this->regexp) = $header;
36 3
        $this->request = $request;
37 3
    }
38
39 2
    public function extract() : string
40
    {
41 2
        $token = $this->request->headers->get($this->header);
42
43 2
        if (preg_match($this->regexp, $token, $matches)) {
44 1
            return $matches[1];
45
        }
46
47 1
        return '';
48
    }
49
}
50