Completed
Push — develop ( e7f1f5...7cd627 )
by Risan Bagja
04:06
created

OAuth1::getHttpClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Risan\OAuth1;
4
5
use Risan\OAuth1\Credentials\ClientCredentials;
6
use Risan\OAuth1\Request\RequestConfigInterface;
7
use Risan\OAuth1\Credentials\TemporaryCredentials;
8
use Risan\OAuth1\Credentials\CredentialsFactoryInterface;
9
10
class OAuth1 implements OAuth1Interface
11
{
12
    /**
13
     * The RequestConfigInterface instance.
14
     *
15
     * @var \Risan\OAuth1\Request\RequestConfigInterface
16
     */
17
    protected $requestConfig;
18
19
    /**
20
     * The HttpClientInterface instance.
21
     *
22
     * @var \Risan\OAuth1\HttpClientInterface
23
     */
24
    protected $httpClient;
25
26
    /**
27
     * The CredentialsFactoryInterface instance.
28
     *
29
     * @var \Risan\OAuth1\Credentials\CredentialsFactoryInterface
30
     */
31
    protected $credentialsFactory;
32
33
    /**
34
     * Create a new OAuth1 instance.
35
     *
36
     * @param \Risan\OAuth1\Request\RequestConfigInterface $requestConfig
37
     * @param \Risan\OAuth1\HttpClientInterface $httpClient
38
     * @param \Risan\OAuth1\Credentials\CredentialsFactoryInterface $credentialsFactory
39
     */
40 7
    public function __construct(RequestConfigInterface $requestConfig, HttpClientInterface $httpClient, CredentialsFactoryInterface $credentialsFactory)
41
    {
42 7
        $this->requestConfig = $requestConfig;
43 7
        $this->httpClient = $httpClient;
44 7
        $this->credentialsFactory = $credentialsFactory;
45 7
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 1
    public function getRequestConfig()
51
    {
52 1
        return $this->requestConfig;
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58 1
    public function getHttpClient()
59
    {
60 1
        return $this->httpClient;
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66 1
    public function getCredentialsFactory()
67
    {
68 1
        return $this->credentialsFactory;
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     */
74 1
    public function getTemporaryCredentials()
75
    {
76 1
        $response = $this->httpClient->post($this->requestConfig->getTemporaryCredentialsUrl(), [
77
            'headers' => [
78 1
                'Authorization' => $this->requestConfig->getTemporaryCredentialsAuthorizationHeader(),
79
            ],
80
        ]);
81
82 1
        return $this->credentialsFactory->createTemporaryCredentialsFromResponse($response);
83
    }
84
85
    /**
86
     * {@inheritDoc}
87
     */
88 1
    public function buildAuthorizationUrl(TemporaryCredentials $temporaryCredentials)
89
    {
90 1
        return $this->requestConfig->buildAuthorizationUrl($temporaryCredentials);
91
    }
92
}
93