Completed
Pull Request — master (#343)
by Luc
06:52
created

ApiKeyPsr7RequestAuthorizer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A authorize() 0 4 1
1
<?php
2
3
namespace CultuurNet\UDB3\Http;
4
5
use Psr\Http\Message\RequestInterface;
6
use ValueObjects\StringLiteral\StringLiteral;
7
8
class ApiKeyPsr7RequestAuthorizer implements Psr7RequestAuthorizerInterface
9
{
10
    /**
11
     * @todo Is it possible to reuse ApiKey from 'cultuurnet/udb3-api-guard'?
12
     * @var StringLiteral
13
     */
14
    private $apiKey;
15
16
    /**
17
     * It is also possible to work without ApiKey, so the ApiKey can be null.
18
     * This can only be covered by setting default null value.
19
     *
20
     * @param StringLiteral $apiKey
21
     */
22
    public function __construct(StringLiteral $apiKey)
23
    {
24
        $this->apiKey = $apiKey;
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function authorize(RequestInterface $request)
31
    {
32
        return $request->withHeader("X-Api-Key", "{$this->apiKey}");
33
    }
34
}