AuthorizationHeaderTokenExtractor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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