Completed
Push — master ( 5ea8f2...3260b6 )
by Tomas
13:58 queued 11s
created

MapboxFactory::configureOptionResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the BazingaGeocoderBundle package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @license    MIT License
9
 */
10
11
namespace Bazinga\GeocoderBundle\ProviderFactory;
12
13
use Geocoder\Provider\Mapbox\Mapbox;
14
use Geocoder\Provider\Provider;
15
use Http\Discovery\HttpClientDiscovery;
16
use Symfony\Component\OptionsResolver\OptionsResolver;
17
18
final class MapboxFactory extends AbstractFactory
19
{
20
    protected static $dependencies = [
21
        ['requiredClass' => Mapbox::class, 'packageName' => 'geocoder-php/mapbox-provider'],
22
    ];
23
24 1
    protected function getProvider(array $config): Provider
25
    {
26 1
        $httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
27
28 1
        return new Mapbox($httplug, $config['api_key'], $config['country'], $config['mode']);
29
    }
30
31 1
    protected static function configureOptionResolver(OptionsResolver $resolver)
32
    {
33 1
        $resolver->setDefaults([
34 1
            'httplug_client' => null,
35
            'country' => null,
36 1
            'mode' => Mapbox::GEOCODING_MODE_PLACES,
37
        ]);
38
39 1
        $resolver->setRequired('api_key');
40 1
        $resolver->setAllowedTypes('api_key', ['string']);
41 1
        $resolver->setAllowedTypes('mode', ['string']);
42 1
        $resolver->setAllowedTypes('httplug_client', ['object', 'null']);
43 1
        $resolver->setAllowedTypes('country', ['string', 'null']);
44 1
    }
45
}
46