Passed
Pull Request — master (#6824)
by
unknown
08:35
created

ProfileSettingsSchema::buildForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 62
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 53
nc 1
nop 1
dl 0
loc 62
rs 9.0254
c 1
b 0
f 0

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\Settings;
8
9
use Chamilo\CoreBundle\Form\Type\YesNoType;
10
use Chamilo\CoreBundle\Transformer\ArrayToIdentifierTransformer;
11
use Sylius\Bundle\SettingsBundle\Schema\AbstractSettingsBuilder;
12
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
13
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
14
use Symfony\Component\Form\Extension\Core\Type\TextType;
15
use Symfony\Component\Form\FormBuilderInterface;
16
17
class ProfileSettingsSchema extends AbstractSettingsSchema
18
{
19
    public function buildSettings(AbstractSettingsBuilder $builder): void
20
    {
21
        $builder
22
            ->setDefaults([
23
                'changeable_options' => ['name', 'officialcode', 'email', 'picture', 'login', 'password', 'language', 'phone', 'theme'],
24
                'extended_profile' => 'false',
25
                'account_valid_duration' => '3660',
26
                'split_users_upload_directory' => 'true',
27
                'user_selected_theme' => 'false',
28
                'use_users_timezone' => 'true',
29
                'allow_users_to_change_email_with_no_password' => 'false',
30
                'login_is_email' => 'false',
31
                'enable_profile_user_address_geolocalization' => '',
32
                'allow_show_skype_account' => '',
33
                'allow_show_linkedin_url' => '',
34
                'hide_username_with_complete_name' => 'false',
35
                'hide_username_in_course_chat' => 'false',
36
                'show_official_code_whoisonline' => 'false',
37
                'my_space_users_items_per_page' => '10',
38
                'add_user_course_information_in_mailto' => 'false',
39
                'pass_reminder_custom_link' => '',
40
                'registration_add_helptext_for_2_names' => 'false',
41
                'send_notification_when_user_added' => '',
42
                'show_conditions_to_user' => '',
43
                'allow_teachers_to_classes' => 'false',
44
                'profile_fields_visibility' => '',
45
                'user_import_settings' => '',
46
                'user_search_on_extra_fields' => '',
47
                'allow_social_map_fields' => '',
48
                'linkedin_organization_id' => 'false',
49
                'visible_options' => ['name', 'officialcode', 'email', 'picture', 'login', 'password', 'language', 'phone', 'theme'],
50
                'show_terms_if_profile_completed' => 'false',
51
            ])
52
            ->setTransformer('changeable_options', new ArrayToIdentifierTransformer())
53
            ->setTransformer('visible_options', new ArrayToIdentifierTransformer())
54
        ;
55
56
        $allowedTypes = [
57
            'changeable_options' => ['array'],
58
            'visible_options' => ['array'],
59
            'account_valid_duration' => ['string'],
60
            'show_terms_if_profile_completed' => ['string'],
61
        ];
62
        $this->setMultipleAllowedTypes($allowedTypes, $builder);
63
    }
64
65
    public function buildForm(FormBuilderInterface $builder): void
66
    {
67
        $builder
68
            ->add('changeable_options', ChoiceType::class, [
69
                'multiple' => true,
70
                'choices' => [
71
                    'Name' => 'name',
72
                    'Official code' => 'officialcode',
73
                    'E-mail' => 'email',
74
                    'Picture' => 'picture',
75
                    'Login' => 'login',
76
                    'Password' => 'password',
77
                    'Language' => 'language',
78
                    'Phone' => 'phone',
79
                    'Theme' => 'theme',
80
                ],
81
            ])
82
            ->add('visible_options', ChoiceType::class, [
83
                'multiple' => true,
84
                'choices' => [
85
                    'Name' => 'name',
86
                    'Official code' => 'officialcode',
87
                    'E-mail' => 'email',
88
                    'Picture' => 'picture',
89
                    'Login' => 'login',
90
                    'Password' => 'password',
91
                    'Language' => 'language',
92
                    'Phone' => 'phone',
93
                    'Theme' => 'theme',
94
                ],
95
            ])
96
            ->add('extended_profile', YesNoType::class)
97
            ->add('account_valid_duration')
98
            ->add('split_users_upload_directory', YesNoType::class)
99
            ->add('user_selected_theme', YesNoType::class)
100
            ->add('use_users_timezone', YesNoType::class)
101
            ->add('allow_users_to_change_email_with_no_password', YesNoType::class)
102
            ->add('login_is_email', YesNoType::class, [
103
                'label' => 'LoginIsEmailTitle',
104
            ])
105
            ->add('enable_profile_user_address_geolocalization', YesNoType::class)
106
            ->add('allow_show_skype_account', YesNoType::class)
107
            ->add('allow_show_linkedin_url', YesNoType::class)
108
            ->add('hide_username_with_complete_name', YesNoType::class)
109
            ->add('hide_username_in_course_chat', YesNoType::class)
110
            ->add('show_official_code_whoisonline', YesNoType::class)
111
            ->add('my_space_users_items_per_page', TextType::class)
112
            ->add('add_user_course_information_in_mailto', YesNoType::class)
113
            ->add('pass_reminder_custom_link', TextType::class)
114
            ->add('registration_add_helptext_for_2_names', YesNoType::class)
115
            ->add('send_notification_when_user_added', TextareaType::class)
116
            ->add('show_conditions_to_user', TextareaType::class)
117
            ->add('allow_teachers_to_classes', YesNoType::class)
118
            ->add('profile_fields_visibility', TextareaType::class)
119
            ->add('user_import_settings', TextareaType::class)
120
            ->add('user_search_on_extra_fields', TextareaType::class)
121
            ->add('allow_social_map_fields', TextareaType::class)
122
            ->add('linkedin_organization_id', YesNoType::class)
123
            ->add('show_terms_if_profile_completed', YesNoType::class)
124
        ;
125
126
        $this->updateFormFieldsFromSettingsInfo($builder);
127
    }
128
}
129