HeaderExtractor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace Equip\Auth\Token;
3
4
use Psr\Http\Message\ServerRequestInterface;
5
6
/**
7
 * Extracts an authentication token from a request header.
8
 */
9
class HeaderExtractor implements ExtractorInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $header;
15
16
    /**
17
     * @param string $header Name of the request header
18
     */
19 4
    public function __construct($header)
20
    {
21 4
        $this->header = (string) $header;
22 4
    }
23
24
    /**
25
     * @inheritDoc
26
     */
27 4
    public function getToken(ServerRequestInterface $request)
28
    {
29 4
        $token = current($request->getHeader($this->header));
30 4
        return $token ?: null;
31
    }
32
}
33