RateTypeType   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
 * This file is part of the Exchange Rate Bundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\ExchangeRate\Form\Type;
11
12
use RunOpenCode\ExchangeRate\Configuration;
13
use RunOpenCode\ExchangeRate\Contract\RatesConfigurationRegistryInterface;
14
use Symfony\Component\Form\AbstractType;
15
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
16
use Symfony\Component\OptionsResolver\OptionsResolver;
17
18
/**
19
 * Class RateTypeType
20
 *
21
 * Rate type choices.
22
 *
23
 * @package RunOpenCode\Bundle\ExchangeRate\Form\Type
24
 */
25 View Code Duplication
class RateTypeType 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...
26
{
27
    /**
28
     * @var array
29
     */
30
    protected $defaults;
31
32 6
    public function __construct(RatesConfigurationRegistryInterface $registry, array $defaults = [])
33
    {
34 6
        $choices = [];
35
36
        /**
37
         * @var Configuration $configuration
38
         */
39 6
        foreach ($registry as $configuration) {
40 6
            $rateType = $configuration->getRateType();
41 6
            $choices[$rateType] = $rateType;
42
        }
43
44 6
        $this->defaults = array_merge(array(
45 6
            'choice_translation_domain' => 'runopencode_exchange_rate',
46 6
            'choices' => $choices
47 6
        ), $defaults);
48 6
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 5
    public function configureOptions(OptionsResolver $resolver)
54
    {
55 5
        $resolver->setDefaults($this->defaults);
56 5
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 5
    public function getParent()
62
    {
63 5
        return ChoiceType::class;
64
    }
65
}
66