Completed
Push — develop ( 470834...262225 )
by Risan Bagja
03:34
created

RequestFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 92.59%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 5
dl 0
loc 115
ccs 25
cts 27
cp 0.9259
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAuthorizationHeader() 0 4 1
A getConfig() 0 4 1
A getUriParser() 0 4 1
A createForTemporaryCredentials() 0 8 1
A buildAuthorizationUri() 0 7 1
A createForTokenCredentials() 0 11 1
A createForProtectedResource() 0 8 1
A create() 0 4 1
1
<?php
2
3
namespace Risan\OAuth1\Request;
4
5
use Risan\OAuth1\Credentials\TokenCredentials;
6
use Risan\OAuth1\Credentials\TemporaryCredentials;
7
8
class RequestFactory implements RequestFactoryInterface
9
{
10
    /**
11
     * The AuthorizationHeaderInterface instance.
12
     *
13
     * @var \Risan\OAuth1\Request\AuthorizationHeaderInterface
14
     */
15
    protected $authorizationHeader;
16
17
    /**
18
     * The UriParserInterface instance.
19
     *
20
     * @var \Risan\OAuth1\Request\UriParserInterface
21
     */
22
    protected $uriParser;
23
24
    /**
25
     * Create the new instance of RequestFactory class.
26
     *
27
     * @param \Risan\OAuth1\Request\AuthorizationHeaderInterface $authorizationHeader
28
     * @param \Risan\OAuth1\Request\UriParserInterface $uriParser
29
     */
30 9
    public function __construct(AuthorizationHeaderInterface $authorizationHeader, UriParserInterface $uriParser)
31
    {
32 9
        $this->authorizationHeader = $authorizationHeader;
33 9
        $this->uriParser = $uriParser;
34 9
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39 1
    public function getAuthorizationHeader()
40
    {
41 1
        return $this->authorizationHeader;
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47 1
    public function getConfig()
48
    {
49 1
        return $this->authorizationHeader->getConfig();
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55 1
    public function getUriParser()
56
    {
57 1
        return $this->uriParser;
58
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63 1
    public function createForTemporaryCredentials()
64
    {
65 1
        return $this->create('POST', (string) $this->getConfig()->getTemporaryCredentialsUri(), [
66
            'headers' => [
67 1
                'Authorization' => $this->authorizationHeader->forTemporaryCredentials(),
68
            ],
69
        ]);
70
    }
71
72
    /**
73
     * {@inheritDoc}
74
     */
75 1
    public function buildAuthorizationUri(TemporaryCredentials $temporaryCredentials)
76
    {
77 1
        return $this->uriParser->appendQueryParameters(
78 1
            $this->getConfig()->getAuthorizationUri(),
79 1
            ['oauth_token' => $temporaryCredentials->getIdentifier()]
80
        );
81
    }
82
83
    /**
84
     * {@inheritDoc}
85
     */
86 1
    public function createForTokenCredentials(TemporaryCredentials $temporaryCredentials, $verificationCode)
87
    {
88 1
        return $this->create('POST', (string) $this->getConfig()->getTokenCredentialsUri(), [
89
            'headers' => [
90 1
                'Authorization' => $this->authorizationHeader->forTokenCredentials($temporaryCredentials, $verificationCode),
91
            ],
92
            'form_params' => [
93 1
                'oauth_verifier' => $verificationCode,
94
            ],
95
        ]);
96
    }
97
98
    /**
99
     * {@inheritDoc}
100
     */
101 1
    public function createForProtectedResource(TokenCredentials $tokenCredentials, $method, $uri, array $options = [])
102
    {
103 1
        return $this->create($method, (string) $this->getConfig()->buildUri($uri), array_replace_recursive([
104
            'headers' => [
105 1
                'Authorization' => $this->authorizationHeader->forProtectedResource($tokenCredentials, $method, $uri, $options),
106
            ]
107 1
        ], $options));
108
    }
109
110
    /**
111
     * Create a new instance of Request class.
112
     *
113
     * @param  string $method
114
     * @param  string $uri
115
     * @param  array  $options [description]
116
     * @return \Risan\OAuth1\Request\RequestInterface
117
     */
118
    public function create($method, $uri, array $options = [])
119
    {
120
        return new Request($method, $uri, $options);
121
    }
122
}
123