BasicAuth::before_request()   A
last analyzed

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