Completed
Push — master ( a814e0...392de1 )
by Tobias
24:09
created

GoogleMapsFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getProvider() 0 6 2
A configureOptionResolver() 0 12 1
1
<?php
2
3
namespace Bazinga\Bundle\GeocoderBundle\ProviderFactory;
4
5
use Geocoder\Provider\GoogleMaps\GoogleMaps;
6
use Http\Client\HttpClient;
7
use Http\Discovery\HttpClientDiscovery;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
10
final class GoogleMapsFactory extends AbstractFactory
11
{
12
    protected static $dependencies = [
13
        ['requiredClass' => GoogleMaps::class, 'packageName' => 'geocoder-php/google-maps-provider'],
14
    ];
15
16
    protected function getProvider(array $config)
17
    {
18
        $httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
19
20
        return new GoogleMaps($httplug, $config['region'], $config['api_key']);
21
    }
22
23
    protected static function configureOptionResolver(OptionsResolver $resolver)
24
    {
25
        $resolver->setDefaults([
26
            'httplug_client' => null,
27
            'region' => null,
28
            'api_key' => null,
29
        ]);
30
31
        $resolver->setAllowedTypes('httplug_client', [HttpClient::class, 'null']);
32
        $resolver->setAllowedTypes('region', ['string', 'null']);
33
        $resolver->setAllowedTypes('api_key', ['string', 'null']);
34
    }
35
}
36