Completed
Push — master ( dba3c8...01cd01 )
by Jean C.
07:48 queued 01:45
created

OAuth::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Moip\Auth;
4
5
use Moip\Contracts\Authentication;
6
use Requests_Hooks;
7
8
/**
9
 * Class OAuth.
10
 */
11
class OAuth implements Authentication
12
{
13
    /**
14
     * Access Token.
15
     *
16
     * @var string
17
     */
18
    private $accessToken;
19
20
    /**
21
     * Create a new OAuth instance.
22
     *
23
     * @param string $accessToken
24
     */
25
    public function __construct($accessToken)
26
    {
27
        $this->accessToken = $accessToken;
28
    }
29
30
    /**
31
     * Register hooks as needed.
32
     *
33
     * This method is called in {@see Requests::request} when the user has set
34
     * an instance as the 'auth' option. Use this callback to register all the
35
     * hooks you'll need.
36
     *
37
     * @see \Requests_Hooks::register
38
     *
39
     * @param \Requests_Hooks $hooks Hook system
40
     */
41
    public function register(Requests_Hooks &$hooks)
42
    {
43
        $hooks->register('requests.before_request', [&$this, 'before_request']);
44
    }
45
46
    /**
47
     * Sets the authentication header.
48
     *
49
     * @param string       $url
50
     * @param array        $headers
51
     * @param array|string $data
52
     * @param string       $type
53
     * @param array        $options
54
     */
55
    public function before_request(&$url, &$headers, &$data, &$type, &$options)
56
    {
57
        $headers['Authorization'] = 'OAuth '.$this->accessToken;
58
    }
59
}
60