SourceType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 41
loc 41
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 4 4 1
A getParent() 4 4 1
A __construct() 17 17 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
namespace RunOpenCode\Bundle\ExchangeRate\Form\Type;
4
5
use RunOpenCode\ExchangeRate\Configuration;
6
use RunOpenCode\ExchangeRate\Contract\RatesConfigurationRegistryInterface;
7
use Symfony\Component\Form\AbstractType;
8
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
9
use Symfony\Component\OptionsResolver\OptionsResolver;
10
11
/**
12
 * Class SourceType
13
 *
14
 * Source choices type.
15
 *
16
 * @package RunOpenCode\Bundle\ExchangeRate\Form\Type
17
 */
18 View Code Duplication
class SourceType extends AbstractType
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
    /**
21
     * @var array
22
     */
23
    protected $defaults;
24
25 6
    public function __construct(RatesConfigurationRegistryInterface $registry, array $defaults = [])
26
    {
27 6
        $choices = [];
28
29
        /**
30
         * @var Configuration $configuration
31
         */
32 6
        foreach ($registry as $configuration) {
33 6
            $sourceName = $configuration->getSourceName();
34 6
            $choices[$sourceName] = $sourceName;
35
        }
36
37 6
        $this->defaults = array_merge(array(
38 6
            'choice_translation_domain' => 'runopencode_exchange_rate',
39 6
            'choices' => $choices
40 6
        ), $defaults);
41 6
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 5
    public function configureOptions(OptionsResolver $resolver)
47
    {
48 5
        $resolver->setDefaults($this->defaults);
49 5
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 5
    public function getParent()
55
    {
56 5
        return ChoiceType::class;
57
    }
58
}
59