Completed
Push — develop ( 41c5da...ffd911 )
by Risan Bagja
02:39
created

OAuth1Factory::create()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 4
nop 2
dl 0
loc 23
ccs 13
cts 13
cp 1
crap 3
rs 9.0856
c 0
b 0
f 0
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
     *
24
     * @return \Risan\OAuth1\OAuth1Interface
25
     */
26 2
    public static function create(array $config, $signer = null)
27
    {
28 2
        if (null === $signer) {
29 1
            $signer = new HmacSha1Signer();
30
        }
31
32 2
        if (! $signer instanceof SignerInterface) {
33 1
            throw new InvalidArgumentException('The signer must implement the \Risan\OAuth1\Signature\SignerInterface.');
34
        }
35
36 1
        $configFactory = new ConfigFactory();
37
38 1
        $protocolParameter = new ProtocolParameter(
39 1
            $configFactory->createFromArray($config),
40 1
            $signer,
41 1
            new NonceGenerator()
42
        );
43
44 1
        $authorizationHeader = new AuthorizationHeader($protocolParameter);
45
46 1
        $requestFactory = new RequestFactory($authorizationHeader, new UriParser());
47
48 1
        return new OAuth1(new HttpClient(), $requestFactory, new CredentialsFactory());
49
    }
50
}
51