Completed
Push — develop ( d9e0d9...390864 )
by Risan Bagja
01:33
created

OAuth1Factory::create()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 8.9713
c 0
b 0
f 0
cc 3
eloc 13
nc 4
nop 2
crap 3
1
<?php
2
3
namespace Risan\OAuth1;
4
5
use InvalidArgumentException;
6
use Risan\OAuth1\Request\UriParser;
7
use Risan\OAuth1\Config\ConfigFactory;
8
use Risan\OAuth1\Request\NonceGenerator;
9
use Risan\OAuth1\Request\RequestFactory;
10
use Risan\OAuth1\Signature\HmacSha1Signer;
11
use Risan\OAuth1\Request\ProtocolParameter;
12
use Risan\OAuth1\Signature\SignerInterface;
13
use Risan\OAuth1\Request\AuthorizationHeader;
14
use Risan\OAuth1\Credentials\CredentialsFactory;
15
16
class OAuth1Factory
17
{
18
    /**
19
     * Create the new OAuth1Interface instance.
20
     *
21
     * @param  array  $config
22
     * @param  \Risan\OAuth1\Signature\SignerInterface|null $signer
23
     * @return \Risan\OAuth1\OAuth1Interface
24
     */
25 2
    public static function create(array $config, $signer = null)
26
    {
27 2
        if (null === $signer) {
28 1
            $signer = new HmacSha1Signer;
29
        }
30
31 2
        if (! $signer instanceof SignerInterface) {
32 1
            throw new InvalidArgumentException('The signer must implement the \Risan\OAuth1\Signature\SignerInterface.');
33
        }
34
        
35 1
        $configFactory = new ConfigFactory;
36
37 1
        $protocolParameter = new ProtocolParameter(
38 1
            $configFactory->createFromArray($config),
39 1
            $signer,
40 1
            new NonceGenerator
41
        );
42
43 1
        $authorizationHeader = new AuthorizationHeader($protocolParameter);
44
45 1
        $requestFactory = new RequestFactory($authorizationHeader, new UriParser);
46
47 1
        return new OAuth1(new HttpClient, $requestFactory, new CredentialsFactory);
48
    }
49
}
50