GoogleMapsFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 26
ccs 10
cts 10
cp 1
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
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\Provider\GoogleMaps\GoogleMaps;
16
use Geocoder\Provider\Provider;
17
use Http\Discovery\HttpClientDiscovery;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
20
final class GoogleMapsFactory extends AbstractFactory
21
{
22
    protected static $dependencies = [
23
        ['requiredClass' => GoogleMaps::class, 'packageName' => 'geocoder-php/google-maps-provider'],
24
    ];
25
26 4
    protected function getProvider(array $config): Provider
27
    {
28 4
        $httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
29
30 4
        return new GoogleMaps($httplug, $config['region'], $config['api_key']);
31
    }
32
33 4
    protected static function configureOptionResolver(OptionsResolver $resolver)
34
    {
35 4
        $resolver->setDefaults([
36 4
            'httplug_client' => null,
37
            'region' => null,
38
            'api_key' => null,
39
        ]);
40
41 4
        $resolver->setAllowedTypes('httplug_client', ['object', 'null']);
42 4
        $resolver->setAllowedTypes('region', ['string', 'null']);
43 4
        $resolver->setAllowedTypes('api_key', ['string', 'null']);
44 4
    }
45
}
46