Completed
Push — master ( 1af7dd...c5badb )
by Ryota
01:36
created

Authorization   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A push() 0 4 1
A handle() 0 4 1
1
<?php
2
3
4
namespace Polidog\Esa\Client;
5
6
7
use GuzzleHttp\HandlerStack;
8
use GuzzleHttp\Middleware;
9
use Psr\Http\Message\RequestInterface;
10
11
class Authorization
12
{
13
    /**
14
     * @var string
15
     */
16
    private $accessToken;
17
18
    /**
19
     * @param string $accessToken
20
     */
21
    public function __construct($accessToken)
22
    {
23
        $this->accessToken = $accessToken;
24
    }
25
26
    /**
27
     * @param HandlerStack $stack
28
     */
29
    public function push(HandlerStack $stack)
30
    {
31
        $stack->push(Middleware::mapRequest([$this, 'handle']));
32
    }
33
34
    /**
35
     * @param RequestInterface $request
36
     * @return RequestInterface
37
     */
38
    public function handle(RequestInterface $request)
39
    {
40
        return $request->withHeader('Authorization', 'Bearer '.$this->accessToken);
41
    }
42
43
}
44