ProviderFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 5 1
A __callStatic() 0 17 4
1
<?php
2
3
namespace Risan\OAuth1;
4
5
use InvalidArgumentException;
6
use Risan\OAuth1\Provider\ProviderInterface;
7
8
class ProviderFactory
9
{
10
    /*
11
     * Create the new OAuth1Interface instance based on the provider config.
12
     *
13
     * @param \Risan\OAuth1\Provider\ProviderInterface $provider
14
     * @param array $config
15
     *
16
     * @return \Risan\OAuth1\OAuth1Interface
17
     */
18 2
    public static function create(ProviderInterface $provider, array $config)
19
    {
20 2
        return OAuth1Factory::create(
21 2
            array_merge($provider->getUriConfig(), $config),
22 2
            $provider->getSigner()
23
        );
24
    }
25
26
    /*
27
    * Dynamically handle the OAuth1Interface instance creation.
28
    *
29
    * @param string $name
30
    * @param array $arguments
31
    *
32
    * @return \Risan\OAuth1\OAuth1Interface
33
    * @throws \InvalidArgumentException
34
    */
35 4
    public static function __callStatic($name, array $arguments)
36
    {
37 4
        $providerClassName = '\\Risan\\OAuth1\\Provider\\' . ucfirst($name);
38
39 4
        if (! class_exists($providerClassName)) {
40 2
            throw new InvalidArgumentException("Class {$providerClassName} is not exists.");
41
        }
42
43 2
        if (! isset($arguments[0])) {
44 1
            throw new InvalidArgumentException("You need to pass the configuration array to ProviderFactory::{$name} method.");
45
        }
46
47 1
        if (! is_array($arguments[0])) {
48
            throw new InvalidArgumentException('The configuration parameter must be an array.');
49
        }
50
51 1
        return static::create(new $providerClassName(), $arguments[0]);
52
    }
53
}
54