Completed
Push — master ( 6d6774...64f3ed )
by Jeroen
11:23 queued 05:13
created

StringFormSubmissionType::configureOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 4
cts 4
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Kunstmaan\FormBundle\Form;
4
5
use Symfony\Component\Form\AbstractType;
6
use Symfony\Component\Form\Extension\Core\Type\TextType;
7
use Symfony\Component\Form\FormBuilderInterface;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
10
/**
11
 * The type for the StringFormSubmissionField
12
 */
13 View Code Duplication
class StringFormSubmissionType 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 The 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 1
        $builder->add('value', TextType::class, $fieldOptions);
33 1
    }
34
35 1
    public function configureOptions(OptionsResolver $resolver)
36
    {
37 1
        $resolver->setDefaults(
38
            [
39 1
                'data_class' => 'Kunstmaan\FormBundle\Entity\FormSubmissionFieldTypes\StringFormSubmissionField',
40
                'value_constraints' => [],
41
            ]
42
        );
43 1
    }
44
45
    /**
46
     * @return string
47
     */
48 1
    public function getBlockPrefix()
49
    {
50 1
        return 'kunstmaan_formbundle_stringformsubmissiontype';
51
    }
52
}
53