Completed
Push — master ( 0728e2...7bf439 )
by Tomas
10:58 queued 10s
created

readAuthorizationToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tomaj\NetteApi\Authorization;
6
7
use Tomaj\NetteApi\Misc\IpDetectorInterface;
8
use Tomaj\NetteApi\Misc\TokenRepositoryInterface;
9
10
class QueryApiKeyAuthentication extends TokenAuthorization
11
{
12
    private $queryParamName;
13
14
    public function __construct(string $queryParamName, TokenRepositoryInterface $tokenRepository, IpDetectorInterface $ipDetector)
15
    {
16
        parent::__construct($tokenRepository, $ipDetector);
17
        $this->queryParamName = $queryParamName;
18
    }
19
20
    protected function readAuthorizationToken(): ?string
21
    {
22
        $apiKey = $_GET[$this->queryParamName] ?? null;
23
        if (!$apiKey) {
24
            $this->errorMessage = 'API key is not set';
25
            return null;
26
        }
27
        return $apiKey;
28
    }
29
30
    public function getQueryParamName(): string
31
    {
32
        return $this->queryParamName;
33
    }
34
}
35