OAuth   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A register() 0 4 1
A before_request() 0 4 1
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)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57
        $headers['Authorization'] = 'OAuth '.$this->accessToken;
58
    }
59
}
60