PluginProviderFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 21
ccs 4
cts 7
cp 0.5714
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createPluginProvider() 0 12 3
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 31
    public static function createPluginProvider(array $plugins, $factory, array $config, array $pluginProviderOptions = []): PluginProvider
32
    {
33 31
        if ($factory instanceof ProviderFactoryInterface) {
34 31
            $client = $factory->createProvider($config);
35
        } elseif (is_callable($factory)) {
36
            $client = $factory($config);
37
        } else {
38
            throw new \RuntimeException(sprintf('Second argument to PluginProviderFactory::createPluginProvider must be a "%s" or a callable.', ProviderFactoryInterface::class));
39
        }
40
41 31
        return new PluginProvider($client, $plugins, $pluginProviderOptions);
42
    }
43
}
44