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\Nominatim\Nominatim; |
16
|
|
|
use Geocoder\Provider\Provider; |
17
|
|
|
use Http\Discovery\HttpClientDiscovery; |
18
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
19
|
|
|
|
20
|
|
View Code Duplication |
final class NominatimFactory extends AbstractFactory |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
protected static $dependencies = [ |
23
|
|
|
['requiredClass' => Nominatim::class, 'packageName' => 'geocoder-php/nominatim-provider'], |
24
|
|
|
]; |
25
|
|
|
|
26
|
3 |
|
protected function getProvider(array $config): Provider |
27
|
|
|
{ |
28
|
3 |
|
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find(); |
29
|
|
|
|
30
|
3 |
|
return new Nominatim($httplug, $config['root_url'], $config['user_agent']); |
31
|
|
|
} |
32
|
|
|
|
33
|
3 |
|
protected static function configureOptionResolver(OptionsResolver $resolver) |
34
|
|
|
{ |
35
|
3 |
|
$resolver->setDefaults([ |
36
|
3 |
|
'httplug_client' => null, |
37
|
|
|
'root_url' => 'https://nominatim.openstreetmap.org', |
38
|
|
|
'user_agent' => 'BazingaGeocoderBundle', |
39
|
|
|
]); |
40
|
|
|
|
41
|
3 |
|
$resolver->setAllowedTypes('httplug_client', ['object', 'null']); |
42
|
3 |
|
$resolver->setAllowedTypes('root_url', ['string']); |
43
|
3 |
|
$resolver->setAllowedTypes('user_agent', ['string']); |
44
|
3 |
|
$resolver->setRequired('user_agent'); |
45
|
3 |
|
} |
46
|
|
|
} |
47
|
|
|
|
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.