Passed
Push — master ( 702f24...55adc1 )
by Yannick
09:28
created

RegistrationSettingsSchema::buildForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 39
nc 1
nop 1
dl 0
loc 52
rs 9.296
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\FormBuilderInterface;
15
16
class RegistrationSettingsSchema extends AbstractSettingsSchema
17
{
18
    public function buildSettings(AbstractSettingsBuilder $builder): void
19
    {
20
        $builder
21
            ->setDefaults([
22
                'required_profile_fields' => [],
23
                'allow_registration' => 'false',
24
                'allow_registration_as_teacher' => 'false',
25
                'allow_lostpassword' => 'true',
26
                'extendedprofile_registration' => [],
27
                'extendedprofile_registrationrequired' => [],
28
                'allow_terms_conditions' => 'false',
29
                'student_autosubscribe' => '',
30
                'teacher_autosubscribe' => '',
31
                'drh_autosubscribe' => '',
32
                'sessionadmin_autosubscribe' => '',
33
                'platform_unsubscribe_allowed' => 'false',
34
                'required_extra_fields_in_inscription' => '',
35
                'allow_fields_inscription' => '',
36
                'send_inscription_msg_to_inbox' => 'false',
37
                'redirect_after_login' => '',
38
            ])
39
            ->setTransformer('required_profile_fields', new ArrayToIdentifierTransformer())
40
            ->setTransformer('extendedprofile_registration', new ArrayToIdentifierTransformer())
41
            ->setTransformer('extendedprofile_registrationrequired', new ArrayToIdentifierTransformer())
42
        ;
43
44
        $allowedTypes = [
45
            'required_profile_fields' => ['array'],
46
            'extendedprofile_registration' => ['array'],
47
            'extendedprofile_registrationrequired' => ['array'],
48
            'allow_registration' => ['string'],
49
            'allow_registration_as_teacher' => ['string'],
50
            'allow_lostpassword' => ['string'],
51
        ];
52
        $this->setMultipleAllowedTypes($allowedTypes, $builder);
53
    }
54
55
    public function buildForm(FormBuilderInterface $builder): void
56
    {
57
        $extendedProfileOptions = [
58
            'MyCompetences' => 'mycompetences',
59
            'MyDiplomas' => 'mydiplomas',
60
            'MyTeach' => 'myteach',
61
            'MyPersonalOpenArea' => 'mypersonalopenarea',
62
        ];
63
64
        $builder
65
            ->add('required_profile_fields', ChoiceType::class, [
66
                'multiple' => true,
67
                'choices' => [
68
                    'Official code' => 'officialcode',
69
                    'E-mail' => 'email',
70
                    'Language' => 'language',
71
                    'Phone' => 'phone',
72
                ],
73
            ])
74
            ->add('allow_registration', ChoiceType::class, [
75
                'choices' => [
76
                    'Yes' => 'true',
77
                    'No' => 'false',
78
                    'Mail confirmation' => 'confirmation',
79
                    'Approval' => 'approval',
80
                ],
81
            ])
82
            ->add('allow_registration_as_teacher', YesNoType::class)
83
            ->add('allow_lostpassword', YesNoType::class)
84
            ->add('extendedprofile_registration', ChoiceType::class, [
85
                'multiple' => true,
86
                'choices' => $extendedProfileOptions,
87
            ])
88
            ->add('extendedprofile_registrationrequired', ChoiceType::class, [
89
                'multiple' => true,
90
                'choices' => $extendedProfileOptions,
91
            ])
92
            ->add('allow_terms_conditions', YesNoType::class)
93
            ->add('student_autosubscribe')
94
            ->add('teacher_autosubscribe')
95
            ->add('drh_autosubscribe')
96
            ->add('sessionadmin_autosubscribe')
97
            ->add('platform_unsubscribe_allowed', YesNoType::class)
98
            ->add('required_extra_fields_in_inscription', TextareaType::class)
99
            ->add('allow_fields_inscription', TextareaType::class)
100
            ->add('send_inscription_msg_to_inbox', YesNoType::class)
101
            ->add('redirect_after_login', TextareaType::class, [
102
                'required' => false,
103
            ])
104
        ;
105
106
        $this->updateFormFieldsFromSettingsInfo($builder);
107
    }
108
}
109