Completed
Push — master ( e761a5...0fd153 )
by Tobias
09:58 queued 02:02
created

IpInfoDbFactory::configureOptionResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 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\IpInfoDb\IpInfoDb;
14
use Http\Client\HttpClient;
15
use Http\Discovery\HttpClientDiscovery;
16
use Symfony\Component\OptionsResolver\OptionsResolver;
17
18 View Code Duplication
final class IpInfoDbFactory extends AbstractFactory
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    protected static $dependencies = [
21
        ['requiredClass' => IpInfoDb::class, 'packageName' => 'geocoder-php/ip-info-db-provider'],
22
    ];
23
24
    protected function getProvider(array $config)
25
    {
26
        $httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
27
28
        return new IpInfoDb($httplug, $config['api_key'], $config['precision']);
29
    }
30
31
    protected static function configureOptionResolver(OptionsResolver $resolver)
32
    {
33
        $resolver->setDefaults([
34
            'httplug_client' => null,
35
            'precision' => 'city',
36
        ]);
37
38
        $resolver->setRequired('api_key');
39
        $resolver->setAllowedTypes('httplug_client', [HttpClient::class, 'null']);
40
        $resolver->setAllowedTypes('api_key', ['string']);
41
        $resolver->setAllowedTypes('precision', ['string']);
42
    }
43
}
44