MaxMindFactory   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 12
cts 12
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\MaxMind\MaxMind;
16
use Geocoder\Provider\Provider;
17
use Http\Discovery\HttpClientDiscovery;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
20
final class MaxMindFactory extends AbstractFactory
21
{
22
    protected static $dependencies = [
23
        ['requiredClass' => MaxMind::class, 'packageName' => 'geocoder-php/maxmind-provider'],
24
    ];
25
26 1
    protected function getProvider(array $config): Provider
27
    {
28 1
        $httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
29
30 1
        return new MaxMind($httplug, $config['api_key'], $config['endpoint']);
31
    }
32
33 1
    protected static function configureOptionResolver(OptionsResolver $resolver)
34
    {
35 1
        $resolver->setDefaults([
36 1
            'httplug_client' => null,
37 1
            'endpoint' => MaxMind::CITY_EXTENDED_SERVICE,
38
        ]);
39
40 1
        $resolver->setRequired('api_key');
41 1
        $resolver->setAllowedTypes('httplug_client', ['object', 'null']);
42 1
        $resolver->setAllowedTypes('api_key', ['string']);
43 1
        $resolver->setAllowedValues('endpoint', [MaxMind::CITY_EXTENDED_SERVICE, MaxMind::OMNI_SERVICE]);
44 1
    }
45
}
46