Completed
Push — master ( 720695...de9ede )
by Fabien
14:35
created

PluginClientFactory::createPluginClient()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.4746

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 8
cp 0.625
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 4
crap 3.4746
1
<?php
2
3
namespace Http\HttplugBundle\ClientFactory;
4
5
use Http\Client\Common\Plugin;
6
use Http\Client\Common\PluginClient;
7
8
/**
9
 * This factory creates a PluginClient.
10
 *
11
 * @author Tobias Nyholm <[email protected]>
12
 */
13
final class PluginClientFactory
14
{
15
    /**
16
     * @param Plugin[]               $plugins
17
     * @param ClientFactory|callable $factory
18
     * @param array                  $config              config to the client factory
19
     * @param array                  $pluginClientOptions config forwarded to the PluginClient
20
     *
21
     * @return PluginClient
22
     */
23 4
    public static function createPluginClient(array $plugins, $factory, array $config, array $pluginClientOptions = [])
24
    {
25 4
        if ($factory instanceof ClientFactory) {
26 4
            $client = $factory->createClient($config);
27 4
        } elseif (is_callable($factory)) {
28
            $client = $factory($config);
29
        } else {
30
            throw new \RuntimeException(sprintf('Second argument to PluginClientFactory::createPluginClient must be a "%s" or a callable.', ClientFactory::class));
31
        }
32
33 4
        return new PluginClient($client, $plugins, $pluginClientOptions);
34
    }
35
}
36