GeoIPsFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 26
loc 26
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptionResolver() 10 10 1
A getProvider() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\GeoIPs\GeoIPs;
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/965
22
 */
23 View Code Duplication
final class GeoIPsFactory 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' => GeoIPs::class, 'packageName' => 'geocoder-php/geoips-provider'],
27
    ];
28
29 1
    protected function getProvider(array $config): Provider
30
    {
31 1
        @trigger_error('Bazinga\GeocoderBundle\ProviderFactory\GeoIPsFactory is deprecated since 5.6, to be removed in 6.0. See https://github.com/geocoder-php/Geocoder/issues/965', 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 GeoIPs($httplug, $config['api_key']);
0 ignored issues
show
Deprecated Code introduced by
The class Geocoder\Provider\GeoIPs\GeoIPs has been deprecated with message: The GeoIPs provider has shut down

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