OpenCageFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
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 24
loc 24
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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

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