Completed
Push — master ( 793b78...9d2cc3 )
by Jesus
01:55
created

validator   D

Complexity

Total Complexity 58

Size/Duplication

Total Lines 272
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 272
rs 4.5599
c 0
b 0
f 0
wmc 58
lcom 0
cbo 0

23 Methods

Rating   Name   Duplication   Size   Complexity  
A section_general_shown() 0 5 2
B section_record_meeting_shown() 0 10 7
A section_import_recordings_shown() 0 5 2
B section_show_recordings_shown() 0 13 9
A section_wait_moderator_shown() 0 7 4
A section_static_voice_bridge_shown() 0 4 1
A section_preupload_presentation_shown() 0 4 1
A section_user_limit_shown() 0 5 2
A section_scheduled_duration_shown() 0 4 1
A section_moderator_default_shown() 0 4 1
A section_send_notifications_shown() 0 4 1
A section_clienttype_shown() 0 12 5
A section_settings_extended_shown() 0 5 2
A section_muteonstart_shown() 0 5 2
A section_disablecam_shown() 0 5 2
A section_disablemic_shown() 0 5 2
A section_disableprivatechat_shown() 0 5 2
A section_disablepublicchat_shown() 0 5 2
A section_disablenote_shown() 0 5 2
A section_hideuserlist_shown() 0 5 2
A section_lockedlayout_shown() 0 5 2
A section_lockonjoin_shown() 0 5 2
A section_lockonjoinconfigurable_shown() 0 5 2

How to fix   Complexity   

Complex Class

Complex classes like validator often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use validator, and based on these observations, apply Extract Interface, too.

1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17
/**
18
 * The mod_bigbluebuttonbn settings/validator.
19
 *
20
 * @package   mod_bigbluebuttonbn
21
 * @copyright 2010 onwards, Blindside Networks Inc
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
24
 */
25
26
namespace mod_bigbluebuttonbn\settings;
27
28
defined('MOODLE_INTERNAL') || die();
29
30
require_once($CFG->dirroot . '/mod/bigbluebuttonbn/locallib.php');
31
require_once($CFG->libdir.'/adminlib.php');
32
33
/**
34
 * Helper class for validating settings used HTML for settings.php.
35
 *
36
 * @copyright 2010 onwards, Blindside Networks Inc
37
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class validator {
40
41
    /**
42
     * Validate if general section will be shown.
43
     *
44
     * @return boolean
45
     */
46
    public static function section_general_shown() {
47
        global $CFG;
48
        return (!isset($CFG->bigbluebuttonbn['server_url']) ||
49
                !isset($CFG->bigbluebuttonbn['shared_secret']));
50
    }
51
52
    /**
53
     * Validate if record meeting section  will be shown.
54
     *
55
     * @return boolean
56
     */
57
    public static function section_record_meeting_shown() {
58
        global $CFG;
59
        return (!isset($CFG->bigbluebuttonbn['recording_default']) ||
60
                !isset($CFG->bigbluebuttonbn['recording_editable']) ||
61
                !isset($CFG->bigbluebuttonbn['recording_icons_enabled']) ||
62
                !isset($CFG->bigbluebuttonbn['recording_all_from_start_default']) ||
63
                !isset($CFG->bigbluebuttonbn['recording_all_from_start_editable']) ||
64
                !isset($CFG->bigbluebuttonbn['recording_hide_button_default']) ||
65
                !isset($CFG->bigbluebuttonbn['recording_hide_button_editable']) );
66
    }
67
68
    /**
69
     * Validate if import recording section will be shown.
70
     *
71
     * @return boolean
72
     */
73
    public static function section_import_recordings_shown() {
74
        global $CFG;
75
        return (!isset($CFG->bigbluebuttonbn['importrecordings_enabled']) ||
76
                !isset($CFG->bigbluebuttonbn['importrecordings_from_deleted_enabled']));
77
    }
78
79
    /**
80
     * Validate if show recording section will be shown.
81
     *
82
     * @return boolean
83
     */
84
    public static function section_show_recordings_shown() {
85
        global $CFG;
86
        return (!isset($CFG->bigbluebuttonbn['recordings_html_default']) ||
87
                !isset($CFG->bigbluebuttonbn['recordings_html_editable']) ||
88
                !isset($CFG->bigbluebuttonbn['recordings_deleted_default']) ||
89
                !isset($CFG->bigbluebuttonbn['recordings_deleted_editable']) ||
90
                !isset($CFG->bigbluebuttonbn['recordings_imported_default']) ||
91
                !isset($CFG->bigbluebuttonbn['recordings_imported_editable']) ||
92
                !isset($CFG->bigbluebuttonbn['recordings_preview_default']) ||
93
                !isset($CFG->bigbluebuttonbn['recordings_preview_editable']) ||
94
                !isset($CFG->bigbluebuttonbn['recordings_validate_url'])
95
              );
96
    }
97
98
    /**
99
     * Validate if wait moderator section will be shown.
100
     *
101
     * @return boolean
102
     */
103
    public static function section_wait_moderator_shown() {
104
        global $CFG;
105
        return (!isset($CFG->bigbluebuttonbn['waitformoderator_default']) ||
106
                !isset($CFG->bigbluebuttonbn['waitformoderator_editable']) ||
107
                !isset($CFG->bigbluebuttonbn['waitformoderator_ping_interval']) ||
108
                !isset($CFG->bigbluebuttonbn['waitformoderator_cache_ttl']));
109
    }
110
111
    /**
112
     * Validate if static voice bridge section will be shown.
113
     *
114
     * @return boolean
115
     */
116
    public static function section_static_voice_bridge_shown() {
117
        global $CFG;
118
        return (!isset($CFG->bigbluebuttonbn['voicebridge_editable']));
119
    }
120
121
    /**
122
     * Validate if preupload presentation section will be shown.
123
     *
124
     * @return boolean
125
     */
126
    public static function section_preupload_presentation_shown() {
127
        global $CFG;
128
        return (!isset($CFG->bigbluebuttonbn['preuploadpresentation_enabled']));
129
    }
130
131
    /**
132
     * Validate if user limit section will be shown.
133
     *
134
     * @return boolean
135
     */
136
    public static function section_user_limit_shown() {
137
        global $CFG;
138
        return (!isset($CFG->bigbluebuttonbn['userlimit_default']) ||
139
                !isset($CFG->bigbluebuttonbn['userlimit_editable']));
140
    }
141
142
    /**
143
     * Validate if scheduled duration section will be shown.
144
     *
145
     * @return boolean
146
     */
147
    public static function section_scheduled_duration_shown() {
148
        global $CFG;
149
        return (!isset($CFG->bigbluebuttonbn['scheduled_duration_enabled']));
150
    }
151
152
    /**
153
     * Validate if moderator default section will be shown.
154
     *
155
     * @return boolean
156
     */
157
    public static function section_moderator_default_shown() {
158
        global $CFG;
159
        return (!isset($CFG->bigbluebuttonbn['participant_moderator_default']));
160
    }
161
162
    /**
163
     * Validate if send notification section will be shown.
164
     *
165
     * @return boolean
166
     */
167
    public static function section_send_notifications_shown() {
168
        global $CFG;
169
        return (!isset($CFG->bigbluebuttonbn['sendnotifications_enabled']));
170
    }
171
172
    /**
173
     * Validate if clienttype section will be shown.
174
     *
175
     * @return boolean
176
     */
177
    public static function section_clienttype_shown() {
178
        global $CFG;
179
        if (!isset($CFG->bigbluebuttonbn['clienttype_enabled']) ||
180
            !$CFG->bigbluebuttonbn['clienttype_enabled']) {
181
            return false;
182
        }
183
        if (!bigbluebuttonbn_has_html5_client()) {
184
            return false;
185
        }
186
        return (!isset($CFG->bigbluebuttonbn['clienttype_default']) ||
187
                !isset($CFG->bigbluebuttonbn['clienttype_editable']));
188
    }
189
190
    /**
191
     * Validate if settings extended section will be shown.
192
     *
193
     * @return boolean
194
     */
195
    public static function section_settings_extended_shown() {
196
        global $CFG;
197
        return (!isset($CFG->bigbluebuttonbn['recordingready_enabled']) ||
198
                !isset($CFG->bigbluebuttonbn['meetingevents_enabled']));
199
    }
200
201
    /**
202
     * Validate if muteonstart section will be shown.
203
     *
204
     * @return boolean
205
     */
206
    public static function section_muteonstart_shown() {
207
        global $CFG;
208
        return (!isset($CFG->bigbluebuttonbn['muteonstart_default']) ||
209
            !isset($CFG->bigbluebuttonbn['muteonstart_editable']));
210
    }
211
212
    /**
213
     * Validate if disablecam section will be shown.
214
     *
215
     * @return boolean
216
     */
217
    public static function section_disablecam_shown() {
218
        global $CFG;
219
        return (!isset($CFG->bigbluebuttonbn['disablecam_default']) ||
220
            !isset($CFG->bigbluebuttonbn['disablecam_editable']));
221
    }
222
223
    /**
224
     * Validate if disablemic section will be shown.
225
     *
226
     * @return boolean
227
     */
228
    public static function section_disablemic_shown() {
229
        global $CFG;
230
        return (!isset($CFG->bigbluebuttonbn['disablemic_default']) ||
231
            !isset($CFG->bigbluebuttonbn['disablemic_editable']));
232
    }
233
234
    /**
235
     * Validate if disableprivatechat section will be shown.
236
     *
237
     * @return boolean
238
     */
239
    public static function section_disableprivatechat_shown() {
240
        global $CFG;
241
        return (!isset($CFG->bigbluebuttonbn['disableprivatechat_default']) ||
242
            !isset($CFG->bigbluebuttonbn['disableprivatechat_editable']));
243
    }
244
245
    /**
246
     * Validate if disablepublicchat section will be shown.
247
     *
248
     * @return boolean
249
     */
250
    public static function section_disablepublicchat_shown() {
251
        global $CFG;
252
        return (!isset($CFG->bigbluebuttonbn['disablepublicchat_default']) ||
253
            !isset($CFG->bigbluebuttonbn['disablepublicchat_editable']));
254
    }
255
256
    /**
257
     * Validate if disablenote section will be shown.
258
     *
259
     * @return boolean
260
     */
261
    public static function section_disablenote_shown() {
262
        global $CFG;
263
        return (!isset($CFG->bigbluebuttonbn['disablenote_default']) ||
264
            !isset($CFG->bigbluebuttonbn['disablenote_editable']));
265
    }
266
267
    /**
268
     * Validate if hideuserlist section will be shown.
269
     *
270
     * @return boolean
271
     */
272
    public static function section_hideuserlist_shown() {
273
        global $CFG;
274
        return (!isset($CFG->bigbluebuttonbn['hideuserlist_default']) ||
275
            !isset($CFG->bigbluebuttonbn['hideuserlist_editable']));
276
    }
277
278
    /**
279
     * Validate if lockedlayout section will be shown.
280
     *
281
     * @return boolean
282
     */
283
    public static function section_lockedlayout_shown() {
284
        global $CFG;
285
        return (!isset($CFG->bigbluebuttonbn['lockedlayout_default']) ||
286
            !isset($CFG->bigbluebuttonbn['lockedlayout_editable']));
287
    }
288
289
    /**
290
     * Validate if lockonjoin section will be shown.
291
     *
292
     * @return boolean
293
     */
294
    public static function section_lockonjoin_shown() {
295
        global $CFG;
296
        return (!isset($CFG->bigbluebuttonbn['lockonjoin_default']) ||
297
            !isset($CFG->bigbluebuttonbn['lockonjoin_editable']));
298
    }
299
300
    /**
301
     * Validate if lockonjoinconfigurable section will be shown.
302
     *
303
     * @return boolean
304
     */
305
    public static function section_lockonjoinconfigurable_shown() {
306
        global $CFG;
307
        return (!isset($CFG->bigbluebuttonbn['lockonjoinconfigurable_default']) ||
308
            !isset($CFG->bigbluebuttonbn['lockonjoinconfigurable_editable']));
309
    }
310
}
311