Passed
Push — master ( ce0ad5...9496a9 )
by Julito
08:27
created

ProfileType::buildForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 64
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 15
c 2
b 1
f 0
nc 1
nop 2
dl 0
loc 64
rs 9.7666

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Form;
8
9
use Chamilo\CoreBundle\Entity\ExtraFieldValues;
10
use Chamilo\CoreBundle\Entity\User;
11
use Chamilo\CoreBundle\Form\Type\IllustrationType;
12
use Chamilo\CoreBundle\Repository\LanguageRepository;
13
use Symfony\Component\Form\AbstractType;
14
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
15
use Symfony\Component\Form\Extension\Core\Type\EmailType;
16
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
17
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
18
use Symfony\Component\Form\Extension\Core\Type\TextType;
19
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
20
use Symfony\Component\Form\Extension\Core\Type\UrlType;
21
use Symfony\Component\Form\FormBuilderInterface;
22
use Symfony\Component\OptionsResolver\OptionsResolver;
23
24
class ProfileType extends AbstractType
25
{
26
    private LanguageRepository $languageRepository;
27
28
    public function __construct(LanguageRepository $languageRepository)
29
    {
30
        $this->languageRepository = $languageRepository;
31
    }
32
33
    public function buildForm(FormBuilderInterface $builder, array $options): void
34
    {
35
        $languages = array_flip($this->languageRepository->getAllAvailableToArray());
36
37
        $builder
38
            ->add('firstname', TextType::class, ['label' => 'Firstname', 'required' => true])
39
            ->add('lastname', TextType::class, ['label' => 'Lastname', 'required' => true])
40
            ->add('email', EmailType::class, ['label' => 'Email', 'required' => true])
41
            //->add('official_code', TextType::class)
42
            //->add('groups')
43
            ->add('locale', LocaleType::class, [
44
                //'preferred_choices' => ['en', 'fr_FR', 'es_ES', 'pt', 'nl'],
45
                'choices' => $languages,
46
                'choice_loader' => null,
47
            ])
48
            /*->add(                'dateOfBirth',
49
                BirthdayType::class,
50
                [
51
                    'label' => 'form.label_date_of_birth',
52
                    'required' => false,
53
                    'widget' => 'single_text',
54
                ]
55
            )
56
            ->add(
57
                'biography',
58
                TextareaType::class,
59
                [
60
                    'label' => 'form.label_biography',
61
                    'required' => false,
62
                ]
63
            )*/
64
            /*->add('locale', 'locale', array(
65
                'label'    => 'form.label_locale',
66
                'required' => false,
67
            ))*/
68
            ->add('timezone', TimezoneType::class, ['label' => 'Timezone', 'required' => true])
69
            ->add('phone', TextType::class, ['label' => 'Phone number', 'required' => false])
70
            ->add(
71
                'illustration',
72
                IllustrationType::class,
73
                ['label' => 'Picture', 'required' => false, 'mapped' => false]
74
            )
75
            //->add('website', UrlType::class, ['label' => 'Website', 'required' => false])
76
            /*->add(
77
                'extraFieldValues',
78
                CollectionType::class,
79
                array(
80
                    'required' => false,
81
                    'allow_add' => true,
82
                    'allow_delete' => true,
83
                    'type' => 'chamilo_user_extra_field_value',
84
                    'by_reference' => false,
85
                    'prototype' => true,
86
                    'widget_add_btn' => ['label' => 'Add'],
87
                    'options' => array( // options for collection fields
88
                        'widget_remove_btn' => array('label' => 'Remove'),
89
                        'label_render' => false,
90
                    )
91
                )
92
            )*/
93
            //->add('save', 'submit', array('label' => 'Update')            )
94
        ;
95
96
        $builder->add('extra_fields', ExtraFieldType::class, ['mapped' => false]);
97
    }
98
99
    public function configureOptions(OptionsResolver $resolver): void
100
    {
101
        $resolver->setDefaults(
102
            [
103
                'data_class' => User::class,
104
            ]
105
        );
106
    }
107
}
108