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

Authorization::push()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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