Completed
Push — master ( 2e7298...3749b5 )
by
unknown
11s
created

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