Completed
Pull Request — master (#343)
by Leny
09:31
created

StaticTextExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3
Metric Value
wmc 4
lcom 0
cbo 3
dl 33
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getExtendedType() 4 4 1
A configureOptions() 8 8 1
A buildView() 7 7 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 Victoire\Bundle\FormBundle\Form\Extension;
4
5
/*
6
 * This file is part of the MopaBootstrapBundle.
7
 *
8
 * (c) Philipp A. Mohrenweiser <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
use Symfony\Component\Form\AbstractTypeExtension;
15
use Symfony\Component\Form\Extension\Core\Type\FormType;
16
use Symfony\Component\Form\FormInterface;
17
use Symfony\Component\Form\FormView;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
20
/**
21
 * Extension for creating static text (form-control-static).
22
 *
23
 * @author peshi <[email protected]>
24
 */
25 View Code Duplication
class StaticTextExtension extends AbstractTypeExtension
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
     * {@inheritdoc}
29
     */
30
    public function getExtendedType()
31
    {
32
        return FormType::class;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function configureOptions(OptionsResolver $resolver)
39
    {
40
        $resolver->setDefaults(
41
            [
42
                'vic_static_text' => null,
43
            ]
44
        );
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function buildView(FormView $view, FormInterface $form, array $options)
51
    {
52
        $view->vars['vic_static_text'] = $options['vic_static_text'];
53
        if ($options['vic_static_text'] == true) {
54
            $view->vars['disabled'] = true;
55
        }
56
    }
57
}
58