Passed
Push — master ( 1c618d...c1c6b0 )
by Yannick
10:36 queued 02:52
created

DocumentSettingsSchema::buildSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 52
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 63
rs 9.0472

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 DocumentSettingsSchema extends AbstractSettingsSchema
17
{
18
    public function buildSettings(AbstractSettingsBuilder $builder): void
19
    {
20
        $builder
21
            ->setDefaults(
22
                [
23
                    'default_document_quotum' => '1000',
24
                    'default_group_quotum' => '250',
25
                    'permanently_remove_deleted_files' => 'false',
26
                    'upload_extensions_list_type' => 'blacklist',
27
                    'upload_extensions_blacklist' => '',
28
                    'upload_extensions_whitelist' => 'htm;html;jpg;jpeg;gif;png;swf;avi;mpg;mpeg;mov;flv;doc;docx;xls;xlsx;ppt;pptx;odt;odp;ods;pdf;webm;oga;ogg;ogv;h264',
29
                    'upload_extensions_skip' => 'true',
30
                    'upload_extensions_replace_by' => 'dangerous',
31
                    'permissions_for_new_directories' => '0777',
32
                    'permissions_for_new_files' => '0666',
33
                    'show_glossary_in_documents' => 'none',
34
                    'students_download_folders' => 'true',
35
                    'users_copy_files' => 'true',
36
                    'pdf_export_watermark_enable' => 'false',
37
                    'pdf_export_watermark_by_course' => 'false',
38
                    'pdf_export_watermark_text' => '',
39
                    'students_export2pdf' => 'true',
40
                    'show_users_folders' => 'true',
41
                    'show_default_folders' => 'true',
42
                    'enabled_text2audio' => 'false',
43
                    // 'enable_nanogong' => 'false',
44
                    'show_documents_preview' => 'false',
45
                    'enable_webcam_clip' => 'false',
46
                    'tool_visible_by_default_at_creation' => [
47
                        'documents',
48
                        'learning_path',
49
                        'links',
50
                        'announcements',
51
                        'forums',
52
                        'quiz',
53
                        'gradebook',
54
                    ],
55
                    'documents_default_visibility_defined_in_course' => 'false',
56
                    'send_notification_when_document_added' => 'false',
57
                    'thematic_pdf_orientation' => 'landscape',
58
                    'certificate_pdf_orientation' => 'landscape',
59
                    'allow_general_certificate' => 'false',
60
                    'group_document_access' => 'false',
61
                    'group_category_document_access' => 'false',
62
                    'allow_compilatio_tool' => 'false',
63
                    'compilatio_tool' => '',
64
                    'documents_hide_download_icon' => 'false',
65
                    'enable_x_sendfile_headers' => 'false',
66
                    'documents_custom_cloud_link_list' => '',
67
                ]
68
            )
69
            ->setTransformer(
70
                'tool_visible_by_default_at_creation',
71
                new ArrayToIdentifierTransformer()
72
            )
73
        ;
74
75
        $allowedTypes = [
76
            'tool_visible_by_default_at_creation' => ['array'],
77
            'default_document_quotum' => ['string'],
78
            'default_group_quotum' => ['string'],
79
        ];
80
        $this->setMultipleAllowedTypes($allowedTypes, $builder);
81
    }
82
83
    public function buildForm(FormBuilderInterface $builder): void
84
    {
85
        $builder
86
            ->add('default_document_quotum')
87
            ->add('default_group_quotum')
88
            ->add('permanently_remove_deleted_files', YesNoType::class)
89
            ->add(
90
                'upload_extensions_list_type',
91
                ChoiceType::class,
92
                [
93
                    'choices' => [
94
                        'Black list' => 'blacklist',
95
                        'White list' => 'whitelist',
96
                    ],
97
                ]
98
            )
99
            ->add('upload_extensions_blacklist', TextareaType::class)
100
            ->add('upload_extensions_whitelist', TextareaType::class)
101
            ->add('upload_extensions_skip', TextareaType::class)
102
            ->add('upload_extensions_replace_by', TextareaType::class)
103
            ->add('permissions_for_new_directories')
104
            ->add('permissions_for_new_files')
105
            ->add(
106
                'show_glossary_in_documents',
107
                ChoiceType::class,
108
                [
109
                    'choices' => [
110
                        'Show glossary in documents is none' => 'none',
111
                        'Show glossary in documents is manual' => 'ismanual',
112
                        'Show glossary in documents is automatic' => 'isautomatic',
113
                    ],
114
                ]
115
            )
116
            ->add('students_download_folders', YesNoType::class)
117
            ->add('users_copy_files', YesNoType::class)
118
            ->add('pdf_export_watermark_enable', YesNoType::class)
119
            ->add('pdf_export_watermark_by_course', YesNoType::class)
120
            ->add('pdf_export_watermark_text', TextareaType::class)
121
            ->add('students_export2pdf', YesNoType::class)
122
            ->add('show_users_folders', YesNoType::class)
123
            ->add('show_default_folders', YesNoType::class)
124
            ->add('enabled_text2audio', YesNoType::class)
125
            // ->add('enable_nanogong', YesNoType::class)
126
            ->add('show_documents_preview', YesNoType::class)
127
            ->add('enable_webcam_clip', YesNoType::class)
128
            ->add(
129
                'tool_visible_by_default_at_creation',
130
                ChoiceType::class,
131
                [
132
                    'multiple' => true,
133
                    'choices' => [
134
                        'Documents' => 'documents',
135
                        'LearningPath' => 'learning_path',
136
                        'Links' => 'links',
137
                        'Announcements' => 'announcements',
138
                        'Forums' => 'forums',
139
                        'Quiz' => 'quiz',
140
                        'Gradebook' => 'gradebook',
141
                    ],
142
                ]
143
            )
144
            ->add('send_notification_when_document_added', YesNoType::class)
145
            ->add(
146
                'thematic_pdf_orientation',
147
                ChoiceType::class,
148
                [
149
                    'choices' => [
150
                        'Portrait' => 'portrait',
151
                        'Landscape' => 'landscape',
152
                    ],
153
                ]
154
            )
155
            ->add(
156
                'certificate_pdf_orientation',
157
                ChoiceType::class,
158
                [
159
                    'choices' => [
160
                        'Portrait' => 'portrait',
161
                        'Landscape' => 'landscape',
162
                    ],
163
                ]
164
            )
165
            ->add('allow_general_certificate', YesNoType::class)
166
            ->add('group_document_access', YesNoType::class)
167
            ->add('group_category_document_access', YesNoType::class)
168
            ->add('allow_compilatio_tool', YesNoType::class)
169
            ->add(
170
                'compilatio_tool',
171
                TextareaType::class,
172
                [
173
                    'help_html' => true,
174
                    'help' => $this->settingArrayHelpValue('compilatio_tool'),
175
                ]
176
            )
177
            ->add('documents_hide_download_icon', YesNoType::class)
178
            ->add('enable_x_sendfile_headers', YesNoType::class)
179
            ->add(
180
                'documents_custom_cloud_link_list',
181
                TextareaType::class,
182
                [
183
                    'help_html' => true,
184
                    'help' => $this->settingArrayHelpValue('documents_custom_cloud_link_list'),
185
                ]
186
            )
187
        ;
188
189
        $this->updateFormFieldsFromSettingsInfo($builder);
190
    }
191
192
    private function settingArrayHelpValue(string $variable): string
193
    {
194
        $values = [
195
            'compilatio_tool' => "<pre>
196
                [
197
                    'settings' => [
198
                        'key' => '',
199
                        'soap_url' => '',
200
                        'proxy_host' => '',
201
                        'proxy_port' => '',
202
                        'max_filesize' => '',
203
                        'transport_mode' => '',
204
                        'wget_uri' => '',
205
                        'wget_login' => '',
206
                        'wget_password' => '',
207
                    ]
208
                ]
209
                </pre>",
210
            'documents_custom_cloud_link_list' => "<pre>
211
                ['links' => ['example.com', 'example2.com']]
212
                </pre>",
213
        ];
214
215
        $returnValue = [];
216
        if (isset($values[$variable])) {
217
            $returnValue = $values[$variable];
218
        }
219
220
        return $returnValue;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $returnValue could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
221
    }
222
}
223