MapzenFactory::configureOptionResolver()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 7
cts 7
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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\Mapzen\Mapzen;
16
use Geocoder\Provider\Provider;
17
use Http\Discovery\HttpClientDiscovery;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
20
/**
21
 * @deprecated since 5.6, to be removed in 6.0. See https://github.com/geocoder-php/Geocoder/issues/808
22
 */
23 View Code Duplication
final class MapzenFactory 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...
24
{
25
    protected static $dependencies = [
26
        ['requiredClass' => Mapzen::class, 'packageName' => 'geocoder-php/mapzen-provider'],
27
    ];
28
29 1
    protected function getProvider(array $config): Provider
30
    {
31 1
        @trigger_error('Bazinga\GeocoderBundle\ProviderFactory\MapzenFactory is deprecated since 5.6, to be removed in 6.0. See https://github.com/geocoder-php/Geocoder/issues/808', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
32
33 1
        $httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
34
35 1
        return new Mapzen($httplug, $config['api_key']);
0 ignored issues
show
Deprecated Code introduced by
The class Geocoder\Provider\Mapzen\Mapzen has been deprecated with message: https://github.com/geocoder-php/Geocoder/issues/808

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
36
    }
37
38 1
    protected static function configureOptionResolver(OptionsResolver $resolver)
39
    {
40 1
        $resolver->setDefaults([
41 1
            'httplug_client' => null,
42
        ]);
43
44 1
        $resolver->setRequired('api_key');
45 1
        $resolver->setAllowedTypes('httplug_client', ['object', 'null']);
46 1
        $resolver->setAllowedTypes('api_key', ['string']);
47 1
    }
48
}
49