Completed
Pull Request — master (#1)
by Woody
23:31 queued 01:08
created

HeaderExtractor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
wmc 3
lcom 1
cbo 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getToken() 0 5 2
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