Completed
Pull Request — master (#1)
by Woody
13:01
created

QueryExtractor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Equip\Auth\Token;
3
4
use Psr\Http\Message\ServerRequestInterface;
5
6
/**
7
 * Extracts an authentication token from a query string parameter.
8
 */
9
class QueryExtractor implements ExtractorInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $parameter;
15
16
    /**
17
     * @param string $parameter Name of the query string parameter
18
     */
19
    public function __construct($parameter)
20
    {
21
        $this->parameter = (string) $parameter;
22
    }
23
24
    /**
25
     * @inheritDoc
26
     */
27
    public function getToken(ServerRequestInterface $request)
28
    {
29
        $query = $request->getQueryParams();
30
        if (isset($query[$this->parameter])) {
31
            return $query[$this->parameter];
32
        }
33
        return null;
34
    }
35
}
36