Completed
Push — master ( 6c4efe...df4b6e )
by Tobias
08:17
created

PluginProviderFactory::createPluginProvider()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.7085

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 4
cts 7
cp 0.5714
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 4
crap 3.7085
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the BazingaGeocoderBundle package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Bazinga\GeocoderBundle\ProviderFactory;
14
15
use Geocoder\Plugin\Plugin;
16
use Geocoder\Plugin\PluginProvider;
17
18
/**
19
 * This factory creates a PluginProvider.
20
 *
21
 * @author Tobias Nyholm <[email protected]>
22
 */
23
final class PluginProviderFactory
24
{
25
    /**
26
     * @param Plugin[]                          $plugins
27
     * @param ProviderFactoryInterface|callable $factory
28
     * @param array                             $config                config to the client factory
29
     * @param array                             $pluginProviderOptions config forwarded to the PluginProvider
30
     *
31
     * @return PluginProvider
32
     */
33 22
    public static function createPluginProvider(array $plugins, $factory, array $config, array $pluginProviderOptions = [])
34
    {
35 22
        if ($factory instanceof ProviderFactoryInterface) {
36 22
            $client = $factory->createProvider($config);
37
        } elseif (is_callable($factory)) {
38
            $client = $factory($config);
39
        } else {
40
            throw new \RuntimeException(sprintf('Second argument to PluginProviderFactory::createPluginProvider must be a "%s" or a callable.', ProviderFactoryInterface::class));
41
        }
42
43 22
        return new PluginProvider($client, $plugins, $pluginProviderOptions);
44
    }
45
}
46