Completed
Pull Request — master (#25)
by Ghazi
21:39
created

CreateMeetingParameters   B

Complexity

Total Complexity 42

Size/Duplication

Total Lines 467
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 42
c 2
b 0
f 0
lcom 2
cbo 1
dl 0
loc 467
rs 8.295

How to fix   Complexity   

Complex Class

Complex classes like CreateMeetingParameters 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 CreateMeetingParameters, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
4
 *
5
 * Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
6
 *
7
 * This program is free software; you can redistribute it and/or modify it under the
8
 * terms of the GNU Lesser General Public License as published by the Free Software
9
 * Foundation; either version 3.0 of the License, or (at your option) any later
10
 * version.
11
 *
12
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License along
17
 * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
namespace BigBlueButton\Parameters;
21
22
/**
23
 * Class CreateMeetingParameters.
24
 */
25
class CreateMeetingParameters extends MetaParameters
26
{
27
    /**
28
     * @var string
29
     */
30
    private $meetingId;
31
32
    /**
33
     * @var string
34
     */
35
    private $meetingName;
36
37
    /**
38
     * @var string
39
     */
40
    private $attendeePassword;
41
42
    /**
43
     * @var string
44
     */
45
    private $moderatorPassword;
46
47
    /**
48
     * @var string
49
     */
50
    private $dialNumber;
51
52
    /**
53
     * @var int
54
     */
55
    private $voiceBridge;
56
57
    /**
58
     * @var string
59
     */
60
    private $webVoice;
61
62
    /**
63
     * @var string
64
     */
65
    private $logoutUrl;
66
67
    /**
68
     * @var int
69
     */
70
    private $maxParticipants;
71
72
    /**
73
     * @var bool
74
     */
75
    private $record;
76
77
    /**
78
     * @var bool
79
     */
80
    private $autoStartRecording;
81
82
    /**
83
     * @var bool
84
     */
85
    private $allowStartStopRecording;
86
87
    /**
88
     * @var int
89
     */
90
    private $duration;
91
92
    /**
93
     * @var string
94
     */
95
    private $welcomeMessage;
96
97
    /**
98
     * @var string
99
     */
100
    private $moderatorOnlyMessage;
101
102
    /**
103
     * @var bool
104
     */
105
    private $webcamsOnlyForModerator;
106
107
    /**
108
     * @var string
109
     */
110
    private $logo;
111
112
    /**
113
     * @var string
114
     */
115
    private $copyright;
116
117
    /**
118
     * @var bool
119
     */
120
    private $muteOnStart;
121
122
    /**
123
     * @var array
124
     */
125
    private $presentations = [];
126
127
    /**
128
     * CreateMeetingParameters constructor.
129
     *
130
     * @param $meetingId
131
     * @param $meetingName
132
     */
133
    public function __construct($meetingId, $meetingName)
134
    {
135
        $this->meetingId   = $meetingId;
136
        $this->meetingName = $meetingName;
137
    }
138
139
    /**
140
     * @return string
141
     */
142
    public function getMeetingId()
143
    {
144
        return $this->meetingId;
145
    }
146
147
    /**
148
     * @param string $meetingId
149
     *
150
     * @return CreateMeetingParameters
151
     */
152
    public function setMeetingId($meetingId)
153
    {
154
        $this->meetingId = $meetingId;
155
156
        return $this;
157
    }
158
159
    /**
160
     * @return string
161
     */
162
    public function getMeetingName()
163
    {
164
        return $this->meetingName;
165
    }
166
167
    /**
168
     * @param string $meetingName
169
     *
170
     * @return CreateMeetingParameters
171
     */
172
    public function setMeetingName($meetingName)
173
    {
174
        $this->meetingName = $meetingName;
175
176
        return $this;
177
    }
178
179
    /**
180
     * @return string
181
     */
182
    public function getAttendeePassword()
183
    {
184
        return $this->attendeePassword;
185
    }
186
187
    /**
188
     * @param string $attendeePassword
189
     *
190
     * @return CreateMeetingParameters
191
     */
192
    public function setAttendeePassword($attendeePassword)
193
    {
194
        $this->attendeePassword = $attendeePassword;
195
196
        return $this;
197
    }
198
199
    /**
200
     * @return string
201
     */
202
    public function getModeratorPassword()
203
    {
204
        return $this->moderatorPassword;
205
    }
206
207
    /**
208
     * @param string $moderatorPassword
209
     *
210
     * @return CreateMeetingParameters
211
     */
212
    public function setModeratorPassword($moderatorPassword)
213
    {
214
        $this->moderatorPassword = $moderatorPassword;
215
216
        return $this;
217
    }
218
219
    /**
220
     * @return string
221
     */
222
    public function getDialNumber()
223
    {
224
        return $this->dialNumber;
225
    }
226
227
    /**
228
     * @param string $dialNumber
229
     *
230
     * @return CreateMeetingParameters
231
     */
232
    public function setDialNumber($dialNumber)
233
    {
234
        $this->dialNumber = $dialNumber;
235
236
        return $this;
237
    }
238
239
    /**
240
     * @return int
241
     */
242
    public function getVoiceBridge()
243
    {
244
        return $this->voiceBridge;
245
    }
246
247
    /**
248
     * @param int $voiceBridge
249
     *
250
     * @return CreateMeetingParameters
251
     */
252
    public function setVoiceBridge($voiceBridge)
253
    {
254
        $this->voiceBridge = $voiceBridge;
255
256
        return $this;
257
    }
258
259
    /**
260
     * @return string
261
     */
262
    public function getWebVoice()
263
    {
264
        return $this->webVoice;
265
    }
266
267
    /**
268
     * @param string $webVoice
269
     *
270
     * @return CreateMeetingParameters
271
     */
272
    public function setWebVoice($webVoice)
273
    {
274
        $this->webVoice = $webVoice;
275
276
        return $this;
277
    }
278
279
    /**
280
     * @return string
281
     */
282
    public function getLogoutUrl()
283
    {
284
        return $this->logoutUrl;
285
    }
286
287
    /**
288
     * @param string $logoutUrl
289
     *
290
     * @return CreateMeetingParameters
291
     */
292
    public function setLogoutUrl($logoutUrl)
293
    {
294
        $this->logoutUrl = $logoutUrl;
295
296
        return $this;
297
    }
298
299
    /**
300
     * @return int
301
     */
302
    public function getMaxParticipants()
303
    {
304
        return $this->maxParticipants;
305
    }
306
307
    /**
308
     * @param int $maxParticipants
309
     *
310
     * @return CreateMeetingParameters
311
     */
312
    public function setMaxParticipants($maxParticipants)
313
    {
314
        $this->maxParticipants = $maxParticipants;
315
316
        return $this;
317
    }
318
319
    /**
320
     * @return bool
321
     */
322
    public function isRecorded()
323
    {
324
        return $this->record;
325
    }
326
327
    /**
328
     * @param bool $record
329
     *
330
     * @return CreateMeetingParameters
331
     */
332
    public function setRecord($record)
333
    {
334
        $this->record = $record;
335
336
        return $this;
337
    }
338
339
    /**
340
     * @return bool
341
     */
342
    public function isAutoStartRecording()
343
    {
344
        return $this->autoStartRecording;
345
    }
346
347
    /**
348
     * @param bool $autoStartRecording
349
     *
350
     * @return CreateMeetingParameters
351
     */
352
    public function setAutoStartRecording($autoStartRecording)
353
    {
354
        $this->autoStartRecording = $autoStartRecording;
355
356
        return $this;
357
    }
358
359
    /**
360
     * @return bool
361
     */
362
    public function isAllowStartStopRecording()
363
    {
364
        return $this->allowStartStopRecording;
365
    }
366
367
    /**
368
     * @param bool $autoStartRecording
369
     *
370
     * @return CreateMeetingParameters
371
     */
372
    public function setAllowStartStopRecording($autoStartRecording)
373
    {
374
        $this->allowStartStopRecording = $autoStartRecording;
375
376
        return $this;
377
    }
378
379
    /**
380
     * @return int
381
     */
382
    public function getDuration()
383
    {
384
        return $this->duration;
385
    }
386
387
    /**
388
     * @param int $duration
389
     *
390
     * @return CreateMeetingParameters
391
     */
392
    public function setDuration($duration)
393
    {
394
        $this->duration = $duration;
395
396
        return $this;
397
    }
398
399
    /**
400
     * @return string
401
     */
402
    public function getWelcomeMessage()
403
    {
404
        return $this->welcomeMessage;
405
    }
406
407
    /**
408
     * @param string $welcomeMessage
409
     *
410
     * @return CreateMeetingParameters
411
     */
412
    public function setWelcomeMessage($welcomeMessage)
413
    {
414
        $this->welcomeMessage = $welcomeMessage;
415
416
        return $this;
417
    }
418
419
    /**
420
     * @return string
421
     */
422
    public function getModeratorOnlyMessage()
423
    {
424
        return $this->moderatorOnlyMessage;
425
    }
426
427
    /**
428
     * @param string $message
429
     *
430
     * @return CreateMeetingParameters
431
     */
432
    public function setModeratorOnlyMessage($message)
433
    {
434
        $this->moderatorOnlyMessage = $message;
435
436
        return $this;
437
    }
438
439
    /**
440
     * @return bool
441
     */
442
    public function isWebcamsOnlyForModerator()
443
    {
444
        return $this->webcamsOnlyForModerator;
445
    }
446
447
    /**
448
     * @param bool $webcamsOnlyForModerator
449
     * @return CreateMeetingParameters
450
     */
451
    public function setWebcamsOnlyForModerator($webcamsOnlyForModerator)
452
    {
453
        $this->webcamsOnlyForModerator = $webcamsOnlyForModerator;
454
        return $this;
455
    }
456
457
    /**
458
     * @return string
459
     */
460
    public function getLogo()
461
    {
462
        return $this->logo;
463
    }
464
465
    /**
466
     * @param string $logo
467
     * @return CreateMeetingParameters
468
     */
469
    public function setLogo($logo)
470
    {
471
        $this->logo = $logo;
472
        return $this;
473
    }
474
475
    /**
476
     * @return string
477
     */
478
    public function getCopyright()
479
    {
480
        return $this->copyright;
481
    }
482
483
    /**
484
     * @param string $copyright
485
     * @return CreateMeetingParameters
486
     */
487
    public function setCopyright($copyright)
488
    {
489
        $this->copyright = $copyright;
490
        return $this;
491
    }
492
493
    /**
494
     * @return bool
495
     */
496
    public function isMuteOnStart()
497
    {
498
        return $this->muteOnStart;
499
    }
500
501
    /**
502
     * @param bool $muteOnStart
503
     * @return CreateMeetingParameters
504
     */
505
    public function setMuteOnStart($muteOnStart)
506
    {
507
        $this->muteOnStart = $muteOnStart;
508
        return $this;
509
    }
510
511
    /**
512
     * @return array
513
     */
514
    public function getPresentations()
515
    {
516
        return $this->presentations;
517
    }
518
519
    /**
520
     * @param $nameOrUrl
521
     * @param null $content
522
     *
523
     * @return CreateMeetingParameters
524
     */
525
    public function addPresentation($nameOrUrl, $content = null)
526
    {
527
        $this->presentations[$nameOrUrl] = !$content ?: base64_encode($content);
528
529
        return $this;
530
    }
531
532
    public function getPresentationsAsXML()
533
    {
534
        $result = '';
535
536
        if (!empty($this->presentations)) {
537
            $xml    = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><modules/>');
538
            $module = $xml->addChild('module');
539
            $module->addAttribute('name', 'presentation');
540
541
            foreach ($this->presentations as $nameOrUrl => $content) {
542
                if ($this->presentations[$nameOrUrl] === true) {
543
                    $module->addChild('document')->addAttribute('url', urlencode($nameOrUrl));
544
                } else {
545
                    $document = $module->addChild('document');
546
                    $document->addAttribute('name', $nameOrUrl);
547
                    $document[0] = $content;
548
                }
549
            }
550
            $result = $xml->asXML();
551
        }
552
553
        return $result;
554
    }
555
556
    /**
557
     * @return string
558
     */
559
    public function getHTTPQuery()
560
    {
561
        $queries = [
562
            'name'                    => $this->meetingName,
563
            'meetingID'               => $this->meetingId,
564
            'attendeePW'              => $this->attendeePassword,
565
            'moderatorPW'             => $this->moderatorPassword,
566
            'dialNumber'              => $this->dialNumber,
567
            'voiceBridge'             => $this->voiceBridge,
568
            'webVoice'                => $this->webVoice,
569
            'logoutURL'               => $this->logoutUrl,
570
            'record'                  => $this->record ? 'true' : 'false',
571
            'duration'                => $this->duration,
572
            'maxParticipants'         => $this->maxParticipants,
573
            'autoStartRecording'      => $this->autoStartRecording ? 'true' : 'false',
574
            'allowStartStopRecording' => $this->allowStartStopRecording ? 'true' : 'false',
575
            'welcome'                 => trim($this->welcomeMessage),
576
            'moderatorOnlyMessage'    => trim($this->moderatorOnlyMessage),
577
            'webcamsOnlyForModerator' => $this->webcamsOnlyForModerator ?  ? 'true' : 'false',
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?'
Loading history...
578
            'logo'                    => $this->logo,
579
            'copyright'               => $this->copyright,
580
            'muteOnStart'             => $this->muteOnStart,
581
        ];
582
583
        $this->buildMeta($queries);
584
585
        return $this->buildHTTPQuery($queries);
586
    }
587
}
588