ProviderFactory::__callStatic()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.0218

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 2
dl 0
loc 17
ccs 8
cts 9
cp 0.8889
crap 4.0218
rs 9.2
c 0
b 0
f 0
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