Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

FileFormSubmissionType   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 41
loc 41
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildForm() 16 16 3
A configureOptions() 9 9 1
A getBlockPrefix() 4 4 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
namespace Kunstmaan\FormBundle\Form;
4
5
use Symfony\Component\Form\AbstractType;
6
use Symfony\Component\Form\Extension\Core\Type\FileType;
7
use Symfony\Component\Form\FormBuilderInterface;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
10
/**
11
 * This class represents the type for the file FileFormSubmissionField
12
 */
13 View Code Duplication
class FileFormSubmissionType 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...
14
{
15
    /**
16
     * @param FormBuilderInterface $builder The form builder
17
     * @param array                $options An array with options
18
     */
19 1
    public function buildForm(FormBuilderInterface $builder, array $options)
20
    {
21 1
        if (isset($options['value_constraints']) && !empty($options['value_constraints'])) {
22
            $options['constraints'] = $options['value_constraints'];
23
        }
24
25 1
        $keys = array_fill_keys(['label', 'required', 'constraints'], null);
26 1
        $fieldOptions = array_filter(
27 1
            array_replace($keys, array_intersect_key($options, $keys)),
28
            function ($v) {
29 1
                return isset($v);
30 1
            }
31
        );
32
33 1
        $builder->add('file', FileType::class, $fieldOptions);
34 1
    }
35
36 1
    public function configureOptions(OptionsResolver $resolver)
37
    {
38 1
        $resolver->setDefaults(
39
            [
40 1
                'data_class' => 'Kunstmaan\FormBundle\Entity\FormSubmissionFieldTypes\FileFormSubmissionField',
41
                'value_constraints' => [],
42
            ]
43
        );
44 1
    }
45
46
    /**
47
     * @return string
48
     */
49 1
    public function getBlockPrefix()
50
    {
51 1
        return 'kunstmaan_formbundle_fileformsubmissiontype';
52
    }
53
}
54