AuthorizationHeader::getConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Risan\OAuth1\Request;
4
5
use Risan\OAuth1\Credentials\TokenCredentials;
6
use Risan\OAuth1\Credentials\TemporaryCredentials;
7
8
class AuthorizationHeader implements AuthorizationHeaderInterface
9
{
10
    /**
11
     * The ProtocolParameterInterface instance.
12
     *
13
     * @var \Risan\OAuth1\Request\ProtocolParameterInterface
14
     */
15
    protected $protocolParameter;
16
17
    /**
18
     * Create a new instance of AuthorizationHeader class.
19
     *
20
     * @param \Risan\OAuth1\Request\ProtocolParameterInterface $protocolParameter
21
     */
22 10
    public function __construct(ProtocolParameterInterface $protocolParameter)
23
    {
24 10
        $this->protocolParameter = $protocolParameter;
25 10
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 3
    public function getProtocolParameter()
31
    {
32 3
        return $this->protocolParameter;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function getConfig()
39
    {
40 1
        return $this->protocolParameter->getConfig();
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function forTemporaryCredentials()
47
    {
48 1
        return $this->normalizeProtocolParameters(
49 1
            $this->protocolParameter->forTemporaryCredentials()
50
        );
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 1
    public function forTokenCredentials(TemporaryCredentials $temporaryCredentials, $verificationCode)
57
    {
58 1
        return $this->normalizeProtocolParameters(
59 1
            $this->protocolParameter->forTokenCredentials($temporaryCredentials, $verificationCode)
60
        );
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 1
    public function forProtectedResource(TokenCredentials $tokenCredentials, $httpMethod, $uri, array $requestOptions = [])
67
    {
68 1
        return $this->normalizeProtocolParameters(
69 1
            $this->protocolParameter->forProtectedResource($tokenCredentials, $httpMethod, $uri, $requestOptions)
70
        );
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function normalizeProtocolParameters(array $parameters)
77
    {
78 4
        array_walk($parameters, function (&$value, $key) {
79 4
            $value = rawurlencode($key) . '="' . rawurlencode($value) . '"';
80 4
        });
81
82 4
        return 'OAuth ' . implode(', ', $parameters);
83
    }
84
}
85