OAuth1Factory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 23 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
     *
24
     * @return \Risan\OAuth1\OAuth1Interface
25
     */
26 5
    public static function create(array $config, $signer = null)
27
    {
28 5
        if (null === $signer) {
29 1
            $signer = new HmacSha1Signer();
30
        }
31
32 5
        if (! $signer instanceof SignerInterface) {
33 1
            throw new InvalidArgumentException('The signer must implement the \Risan\OAuth1\Signature\SignerInterface.');
34
        }
35
36 4
        $configFactory = new ConfigFactory();
37
38 4
        $protocolParameter = new ProtocolParameter(
39 4
            $configFactory->createFromArray($config),
40 4
            $signer,
41 4
            new NonceGenerator()
42
        );
43
44 4
        $authorizationHeader = new AuthorizationHeader($protocolParameter);
45
46 4
        $requestFactory = new RequestFactory($authorizationHeader, new UriParser());
47
48 4
        return new OAuth1(new HttpClient(), $requestFactory, new CredentialsFactory());
49
    }
50
}
51